|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the LGPL. For more information please see |
|
18
|
|
|
* <http://phing.info>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Phing\Task\Ext\Archive; |
|
22
|
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
|
24
|
|
|
use Phing\Project; |
|
25
|
|
|
use Phing\Type\FileSet; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* This is a FileSet with the option to specify permissions. |
|
29
|
|
|
* |
|
30
|
|
|
* Permissions are currently not implemented by PEAR Archive_Tar, |
|
31
|
|
|
* but hopefully they will be in the future. |
|
32
|
|
|
* |
|
33
|
|
|
* @package phing.tasks.ext |
|
34
|
|
|
*/ |
|
35
|
|
|
class TarFileSet extends FileSet |
|
36
|
|
|
{ |
|
37
|
|
|
private $files = null; |
|
38
|
|
|
|
|
39
|
|
|
private $mode = 0100644; |
|
40
|
|
|
|
|
41
|
|
|
private $userName = ""; |
|
42
|
|
|
private $groupName = ""; |
|
43
|
|
|
private $prefix = ""; |
|
44
|
|
|
private $fullpath = ""; |
|
45
|
|
|
private $preserveLeadingSlashes = false; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get a list of files and directories specified in the fileset. |
|
49
|
|
|
* |
|
50
|
|
|
* @param Project $p |
|
51
|
|
|
* @param bool $includeEmpty |
|
52
|
|
|
* |
|
53
|
|
|
* @return array a list of file and directory names, relative to |
|
54
|
|
|
* the baseDir for the project. |
|
55
|
|
|
* |
|
56
|
|
|
* @throws BuildException |
|
57
|
|
|
* @throws \Exception |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getFiles($includeEmpty = true, ...$options) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
if ($this->files === null) { |
|
62
|
|
|
$ds = $this->getDirectoryScanner($this->getProject()); |
|
63
|
|
|
$this->files = $ds->getIncludedFiles(); |
|
64
|
|
|
|
|
65
|
|
|
if ($includeEmpty) { |
|
66
|
|
|
// first any empty directories that will not be implicitly added by any of the files |
|
67
|
|
|
$implicitDirs = []; |
|
68
|
|
|
foreach ($this->files as $file) { |
|
69
|
|
|
$implicitDirs[] = dirname($file); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$incDirs = $ds->getIncludedDirectories(); |
|
73
|
|
|
|
|
74
|
|
|
// we'll need to add to that list of implicit dirs any directories |
|
75
|
|
|
// that contain other *directories* (and not files), since otherwise |
|
76
|
|
|
// we get duplicate directories in the resulting tar |
|
77
|
|
|
foreach ($incDirs as $dir) { |
|
78
|
|
|
foreach ($incDirs as $dircheck) { |
|
79
|
|
|
if (!empty($dir) && $dir == dirname($dircheck)) { |
|
80
|
|
|
$implicitDirs[] = $dir; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$implicitDirs = array_unique($implicitDirs); |
|
86
|
|
|
|
|
87
|
|
|
// Now add any empty dirs (dirs not covered by the implicit dirs) |
|
88
|
|
|
// to the files array. |
|
89
|
|
|
|
|
90
|
|
|
foreach ($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs |
|
91
|
|
|
if ($dir != "" && $dir !== "." && !in_array($dir, $implicitDirs)) { |
|
92
|
|
|
// it's an empty dir, so we'll add it. |
|
93
|
|
|
$this->files[] = $dir; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} // if $includeEmpty |
|
97
|
|
|
} // if ($this->files===null) |
|
98
|
|
|
|
|
99
|
|
|
return $this->files; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* A 3 digit octal string, specify the user, group and |
|
104
|
|
|
* other modes in the standard Unix fashion; |
|
105
|
|
|
* optional, default=0644 |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $octalString |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setMode($octalString) |
|
110
|
|
|
{ |
|
111
|
|
|
$octal = (int) $octalString; |
|
112
|
|
|
$this->mode = 0100000 | $octal; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return int |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getMode() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->mode; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* The username for the tar entry |
|
125
|
|
|
* This is not the same as the UID, which is |
|
126
|
|
|
* not currently set by the task. |
|
127
|
|
|
* |
|
128
|
|
|
* @param $userName |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setUserName($userName) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->userName = $userName; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return string |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getUserName() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->userName; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* The groupname for the tar entry; optional, default="" |
|
145
|
|
|
* This is not the same as the GID, which is |
|
146
|
|
|
* not currently set by the task. |
|
147
|
|
|
* |
|
148
|
|
|
* @param $groupName |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setGroup($groupName) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->groupName = $groupName; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getGroup() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->groupName; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* If the prefix attribute is set, all files in the fileset |
|
165
|
|
|
* are prefixed with that path in the archive. |
|
166
|
|
|
* optional. |
|
167
|
|
|
* |
|
168
|
|
|
* @param bool $prefix |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setPrefix($prefix) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->prefix = $prefix; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @return string |
|
177
|
|
|
*/ |
|
178
|
|
|
public function getPrefix() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->prefix; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* If the fullpath attribute is set, the file in the fileset |
|
185
|
|
|
* is written with that path in the archive. The prefix attribute, |
|
186
|
|
|
* if specified, is ignored. It is an error to have more than one file specified in |
|
187
|
|
|
* such a fileset. |
|
188
|
|
|
* |
|
189
|
|
|
* @param $fullpath |
|
190
|
|
|
*/ |
|
191
|
|
|
public function setFullpath($fullpath) |
|
192
|
|
|
{ |
|
193
|
|
|
$this->fullpath = $fullpath; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @return string |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getFullpath() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->fullpath; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Flag to indicates whether leading `/'s` should |
|
206
|
|
|
* be preserved in the file names. |
|
207
|
|
|
* Optional, default is <code>false</code>. |
|
208
|
|
|
* |
|
209
|
|
|
* @param bool $b |
|
210
|
|
|
* |
|
211
|
|
|
* @return void |
|
212
|
|
|
*/ |
|
213
|
|
|
public function setPreserveLeadingSlashes($b) |
|
214
|
|
|
{ |
|
215
|
|
|
$this->preserveLeadingSlashes = (bool) $b; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return bool |
|
220
|
|
|
*/ |
|
221
|
|
|
public function getPreserveLeadingSlashes() |
|
222
|
|
|
{ |
|
223
|
|
|
return $this->preserveLeadingSlashes; |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.