1
|
|
<?php
|
2
|
|
/**
|
3
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
4
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
5
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
6
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
7
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
8
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
9
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
10
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
11
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
12
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
13
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
|
*
|
15
|
|
* This software consists of voluntary contributions made by many individuals
|
16
|
|
* and is licensed under the LGPL. For more information please see
|
17
|
|
* <http://phing.info>.
|
18
|
|
*/
|
19
|
|
|
20
|
|
/**
|
21
|
|
* Task to create a directory.
|
22
|
|
*
|
23
|
|
* @author Andreas Aderhold, andi@binarycloud.com
|
24
|
|
* @package phing.tasks.system
|
25
|
|
*/
|
26
|
|
class MkdirTask extends Task
|
27
|
|
{
|
28
|
|
|
29
|
|
/**
|
30
|
|
* Directory to create.
|
31
|
|
*
|
32
|
|
* @var PhingFile $dir
|
33
|
|
*/
|
34
|
|
private $dir;
|
35
|
|
|
36
|
|
/**
|
37
|
|
* Mode to create directory with
|
38
|
|
*
|
39
|
|
* @var integer|null
|
40
|
|
*/
|
41
|
|
private $mode = null;
|
42
|
|
|
43
|
|
/**
|
44
|
|
* create the directory and all parents
|
45
|
|
*
|
46
|
|
* @throws BuildException if dir is somehow invalid, or creation failed.
|
47
|
|
*/
|
48
|
1
|
public function main()
|
49
|
|
{
|
50
|
1
|
if ($this->dir === null) {
|
51
|
0
|
throw new BuildException("dir attribute is required", $this->getLocation());
|
52
|
|
}
|
53
|
1
|
if ($this->dir->isFile()) {
|
54
|
0
|
throw new BuildException(
|
55
|
0
|
"Unable to create directory as a file already exists with that name: " . $this->dir->getAbsolutePath()
|
56
|
|
);
|
57
|
|
}
|
58
|
1
|
if (!$this->dir->exists()) {
|
59
|
1
|
$result = $this->dir->mkdirs($this->mode);
|
60
|
1
|
if (!$result) {
|
61
|
0
|
if ($this->dir->exists()) {
|
62
|
0
|
$this->log("A different process or task has already created " . $this->dir->getAbsolutePath());
|
63
|
|
|
64
|
0
|
return;
|
65
|
|
}
|
66
|
0
|
$msg = "Directory " . $this->dir->getAbsolutePath() . " creation was not successful for an unknown reason";
|
67
|
0
|
throw new BuildException($msg, $this->getLocation());
|
68
|
|
}
|
69
|
1
|
$this->log("Created dir: " . $this->dir->getAbsolutePath());
|
70
|
|
} else {
|
71
|
1
|
$this->log(
|
72
|
1
|
'Skipping ' . $this->dir->getAbsolutePath() . ' because it already exists.',
|
73
|
1
|
Project::MSG_VERBOSE
|
74
|
|
);
|
75
|
|
}
|
76
|
|
}
|
77
|
|
|
78
|
|
/**
|
79
|
|
* The directory to create; required.
|
80
|
|
*
|
81
|
|
* @param PhingFile $dir
|
82
|
|
* @return void
|
83
|
|
*/
|
84
|
1
|
public function setDir(PhingFile $dir)
|
85
|
|
{
|
86
|
1
|
$this->dir = $dir;
|
87
|
|
}
|
88
|
|
|
89
|
|
/**
|
90
|
|
* Sets mode to create directory with
|
91
|
|
*
|
92
|
|
* @param mixed $mode
|
93
|
|
* @return void
|
94
|
|
*/
|
95
|
1
|
public function setMode($mode)
|
96
|
|
{
|
97
|
1
|
$this->mode = base_convert((int) $mode, 8, 10);
|
98
|
|
}
|
99
|
|
}
|