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
|
|
* This is a FileSet with the to specify permissions.
|
22
|
|
*
|
23
|
|
* Permissions are currently not implemented by PEAR Archive_Tar,
|
24
|
|
* but hopefully they will be in the future.
|
25
|
|
*
|
26
|
|
* @package phing.tasks.ext
|
27
|
|
*/
|
28
|
|
class ZipFileSet extends FileSet
|
29
|
|
{
|
30
|
|
private $files = null;
|
31
|
|
|
32
|
|
/**
|
33
|
|
* Get a list of files and directories specified in the fileset.
|
34
|
|
*
|
35
|
|
* @param bool $includeEmpty
|
36
|
|
* @param array ...$options
|
37
|
|
*
|
38
|
|
* @return array a list of file and directory names, relative to
|
39
|
|
* the baseDir for the project.
|
40
|
|
*
|
41
|
|
* @throws Exception
|
42
|
|
*/
|
43
|
1
|
protected function getFiles($includeEmpty = true, ...$options)
|
44
|
|
{
|
45
|
1
|
if ($this->files === null) {
|
46
|
1
|
$ds = $this->getDirectoryScanner($this->getProject());
|
47
|
1
|
$this->files = $ds->getIncludedFiles();
|
48
|
|
|
49
|
|
// build a list of directories implicitly added by any of the files
|
50
|
1
|
$implicitDirs = [];
|
51
|
1
|
foreach ($this->files as $file) {
|
52
|
1
|
$implicitDirs[] = dirname($file);
|
53
|
|
}
|
54
|
|
|
55
|
1
|
$incDirs = $ds->getIncludedDirectories();
|
56
|
|
|
57
|
|
// we'll need to add to that list of implicit dirs any directories
|
58
|
|
// that contain other *directories* (and not files), since otherwise
|
59
|
|
// we get duplicate directories in the resulting tar
|
60
|
1
|
foreach ($incDirs as $dir) {
|
61
|
1
|
foreach ($incDirs as $dircheck) {
|
62
|
1
|
if (!empty($dir) && $dir == dirname($dircheck)) {
|
63
|
0
|
$implicitDirs[] = $dir;
|
64
|
|
}
|
65
|
|
}
|
66
|
|
}
|
67
|
|
|
68
|
1
|
$implicitDirs = array_unique($implicitDirs);
|
69
|
|
|
70
|
1
|
$emptyDirectories = [];
|
71
|
|
|
72
|
1
|
if ($includeEmpty) {
|
73
|
|
// Now add any empty dirs (dirs not covered by the implicit dirs)
|
74
|
|
// to the files array.
|
75
|
|
|
76
|
1
|
foreach ($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs
|
77
|
1
|
if ($dir != "" && $dir !== "." && !in_array($dir, $implicitDirs)) {
|
78
|
|
// it's an empty dir, so we'll add it.
|
79
|
0
|
$emptyDirectories[] = $dir;
|
80
|
|
}
|
81
|
|
}
|
82
|
|
} // if $includeEmpty
|
83
|
|
|
84
|
1
|
$this->files = array_merge($implicitDirs, $emptyDirectories, $this->files);
|
85
|
1
|
sort($this->files);
|
86
|
|
} // if ($this->files===null)
|
87
|
|
|
88
|
1
|
return $this->files;
|
89
|
|
}
|
90
|
|
}
|