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