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 option 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 TarFileSet extends FileSet
29
{
30
    private $files = null;
31

32
    private $mode = 0100644;
33

34
    private $userName = "";
35
    private $groupName = "";
36
    private $prefix = "";
37
    private $fullpath = "";
38
    private $preserveLeadingSlashes = false;
39

40
    /**
41
     * Get a list of files and directories specified in the fileset.
42
     *
43
     * @param Project $p
44
     * @param bool $includeEmpty
45
     *
46
     * @return array a list of file and directory names, relative to
47
     *               the baseDir for the project.
48
     *
49
     * @throws BuildException
50
     * @throws Exception
51
     */
52 0
    protected function getFiles($includeEmpty = true, ...$options)
53
    {
54 0
        if ($this->files === null) {
55 0
            $ds = $this->getDirectoryScanner($this->getProject());
56 0
            $this->files = $ds->getIncludedFiles();
57

58 0
            if ($includeEmpty) {
59
                // first any empty directories that will not be implicitly added by any of the files
60 0
                $implicitDirs = [];
61 0
                foreach ($this->files as $file) {
62 0
                    $implicitDirs[] = dirname($file);
63
                }
64

65 0
                $incDirs = $ds->getIncludedDirectories();
66

67
                // we'll need to add to that list of implicit dirs any directories
68
                // that contain other *directories* (and not files), since otherwise
69
                // we get duplicate directories in the resulting tar
70 0
                foreach ($incDirs as $dir) {
71 0
                    foreach ($incDirs as $dircheck) {
72 0
                        if (!empty($dir) && $dir == dirname($dircheck)) {
73 0
                            $implicitDirs[] = $dir;
74
                        }
75
                    }
76
                }
77

78 0
                $implicitDirs = array_unique($implicitDirs);
79

80
                // Now add any empty dirs (dirs not covered by the implicit dirs)
81
                // to the files array.
82

83 0
                foreach ($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs
84 0
                    if ($dir != "" && $dir !== "." && !in_array($dir, $implicitDirs)) {
85
                        // it's an empty dir, so we'll add it.
86 0
                        $this->files[] = $dir;
87
                    }
88
                }
89
            } // if $includeEmpty
90
        } // if ($this->files===null)
91

92 0
        return $this->files;
93
    }
94

95
    /**
96
     * A 3 digit octal string, specify the user, group and
97
     * other modes in the standard Unix fashion;
98
     * optional, default=0644
99
     *
100
     * @param string $octalString
101
     */
102 0
    public function setMode($octalString)
103
    {
104 0
        $octal = (int) $octalString;
105 0
        $this->mode = 0100000 | $octal;
106
    }
107

108
    /**
109
     * @return int
110
     */
111 0
    public function getMode()
112
    {
113 0
        return $this->mode;
114
    }
115

116
    /**
117
     * The username for the tar entry
118
     * This is not the same as the UID, which is
119
     * not currently set by the task.
120
     *
121
     * @param $userName
122
     */
123 0
    public function setUserName($userName)
124
    {
125 0
        $this->userName = $userName;
126
    }
127

128
    /**
129
     * @return string
130
     */
131 0
    public function getUserName()
132
    {
133 0
        return $this->userName;
134
    }
135

136
    /**
137
     * The groupname for the tar entry; optional, default=""
138
     * This is not the same as the GID, which is
139
     * not currently set by the task.
140
     *
141
     * @param $groupName
142
     */
143 0
    public function setGroup($groupName)
144
    {
145 0
        $this->groupName = $groupName;
146
    }
147

148
    /**
149
     * @return string
150
     */
151 0
    public function getGroup()
152
    {
153 0
        return $this->groupName;
154
    }
155

156
    /**
157
     * If the prefix attribute is set, all files in the fileset
158
     * are prefixed with that path in the archive.
159
     * optional.
160
     *
161
     * @param bool $prefix
162
     */
163 0
    public function setPrefix($prefix)
164
    {
165 0
        $this->prefix = $prefix;
166
    }
167

168
    /**
169
     * @return string
170
     */
171 0
    public function getPrefix()
172
    {
173 0
        return $this->prefix;
174
    }
175

176
    /**
177
     * If the fullpath attribute is set, the file in the fileset
178
     * is written with that path in the archive. The prefix attribute,
179
     * if specified, is ignored. It is an error to have more than one file specified in
180
     * such a fileset.
181
     *
182
     * @param $fullpath
183
     */
184 0
    public function setFullpath($fullpath)
185
    {
186 0
        $this->fullpath = $fullpath;
187
    }
188

189
    /**
190
     * @return string
191
     */
192 0
    public function getFullpath()
193
    {
194 0
        return $this->fullpath;
195
    }
196

197
    /**
198
     * Flag to indicates whether leading `/'s` should
199
     * be preserved in the file names.
200
     * Optional, default is <code>false</code>.
201
     *
202
     * @param bool $b
203
     *
204
     * @return void
205
     */
206 0
    public function setPreserveLeadingSlashes($b)
207
    {
208 0
        $this->preserveLeadingSlashes = (bool) $b;
209
    }
210

211
    /**
212
     * @return bool
213
     */
214 0
    public function getPreserveLeadingSlashes()
215
    {
216 0
        return $this->preserveLeadingSlashes;
217
    }
218
}

Read our documentation on viewing source code .

Loading