1 | <?php |
||
20 | class Tar extends Abstraction implements Executable |
||
21 | { |
||
22 | /** |
||
23 | * Path to compress |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $path; |
||
28 | |||
29 | /** |
||
30 | * Compression to use |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $compression; |
||
35 | |||
36 | /** |
||
37 | * Compress program to use. |
||
38 | * --use-compress-program |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $compressProgram; |
||
43 | |||
44 | /** |
||
45 | * Path to dump file |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $tarPathname; |
||
50 | |||
51 | /** |
||
52 | * List of excluded path. |
||
53 | * --exclude='foo' |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | private $excludes = []; |
||
58 | |||
59 | /** |
||
60 | * Ignore failed reads |
||
61 | * --ignore-failed-read |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | 13 | private $ignoreFailedRead; |
|
66 | |||
67 | 13 | /** |
|
68 | 13 | * Should the source directory be removed. |
|
69 | 13 | * |
|
70 | * @var boolean |
||
71 | */ |
||
72 | private $removeSourceDir = false; |
||
73 | |||
74 | /** |
||
75 | * List of available compressors |
||
76 | * |
||
77 | 6 | * @var array |
|
78 | */ |
||
79 | 6 | private static $availableCompressions = [ |
|
80 | 'bzip2' => 'j', |
||
81 | 'gzip' => 'z', |
||
82 | ]; |
||
83 | |||
84 | /** |
||
85 | * Constructor. |
||
86 | * |
||
87 | * @param string $path |
||
88 | 8 | */ |
|
89 | public function __construct(string $path = '') |
||
93 | 8 | ||
94 | /** |
||
95 | * Return 'tar' compressor option e.g. 'j' for bzip2. |
||
96 | * |
||
97 | * @param string $compressor |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function getCompressionOption(string $compressor) : string |
||
104 | |||
105 | /** |
||
106 | * Compress tar. |
||
107 | * |
||
108 | * @param string $compression |
||
109 | * @return \phpbu\App\Cli\Executable\Tar |
||
110 | */ |
||
111 | public function useCompression(string $compression) : Tar |
||
118 | 10 | ||
119 | 10 | /** |
|
120 | * Set compress program. |
||
121 | * |
||
122 | * @param string $program |
||
123 | * @return \phpbu\App\Cli\Executable\Tar |
||
124 | */ |
||
125 | public function useCompressProgram(string $program) : Tar |
||
130 | 9 | ||
131 | 9 | /** |
|
132 | * Add an path to exclude. |
||
133 | * |
||
134 | * @param string $path |
||
135 | * @return \phpbu\App\Cli\Executable\Tar |
||
136 | */ |
||
137 | public function addExclude(string $path) : Tar |
||
142 | 2 | ||
143 | 2 | /** |
|
144 | * Ignore failed reads setter. |
||
145 | * |
||
146 | * @param bool $bool |
||
147 | * @return \phpbu\App\Cli\Executable\Tar |
||
148 | */ |
||
149 | 11 | public function ignoreFailedRead(bool $bool) : Tar |
|
154 | |||
155 | 10 | /** |
|
156 | 1 | * Does the tar handle the compression. |
|
157 | * |
||
158 | * @return bool |
||
159 | 9 | */ |
|
160 | 9 | public function handlesCompression() : bool |
|
164 | 8 | ||
165 | /** |
||
166 | 8 | * Set folder to compress. |
|
167 | * |
||
168 | 9 | * @param string $path |
|
169 | 9 | * @return \phpbu\App\Cli\Executable\Tar |
|
170 | 9 | * @throws \phpbu\App\Exception |
|
171 | 9 | */ |
|
172 | public function archiveDirectory(string $path) : Tar |
||
178 | 2 | ||
179 | /** |
||
180 | 9 | * Set target filename. |
|
181 | * |
||
182 | * @param string $path |
||
183 | * @return \phpbu\App\Cli\Executable\Tar |
||
184 | */ |
||
185 | public function archiveTo(string $path) : Tar |
||
190 | 2 | ||
191 | 2 | /** |
|
192 | 2 | * Delete the source directory. |
|
193 | 2 | * |
|
194 | 2 | * @param boolean $bool |
|
195 | 2 | * @return \phpbu\App\Cli\Executable\Tar |
|
196 | */ |
||
197 | public function removeSourceDirectory(bool $bool) : Tar |
||
202 | |||
203 | /** |
||
204 | 9 | * Tar CommandLine generator. |
|
205 | * |
||
206 | 9 | * @return \SebastianFeldmann\Cli\CommandLine |
|
207 | */ |
||
208 | protected function createCommandLine() : CommandLine |
||
231 | |||
232 | /** |
||
233 | * Adds necessary exclude options to tat command. |
||
234 | * |
||
235 | * @param \SebastianFeldmann\Cli\Command\Executable $tar |
||
236 | */ |
||
237 | protected function setExcludeOptions(Cmd $tar) |
||
243 | |||
244 | /** |
||
245 | * Add a remove command if requested. |
||
246 | * |
||
247 | * @param \SebastianFeldmann\Cli\CommandLine $process |
||
248 | */ |
||
249 | protected function addRemoveCommand(CommandLine $process) |
||
255 | |||
256 | /** |
||
257 | * Return 'rm' command. |
||
258 | * |
||
259 | * @return \SebastianFeldmann\Cli\Command\Executable |
||
260 | */ |
||
261 | protected function getRmCommand() : Cmd |
||
267 | |||
268 | /** |
||
269 | * Check directory to compress. |
||
270 | * |
||
271 | * @param string $path |
||
272 | * @throws \phpbu\App\Exception |
||
273 | */ |
||
274 | private function validateDirectory(string $path) |
||
280 | |||
281 | /** |
||
282 | * Check if source and target values are set. |
||
283 | * |
||
284 | * @throws \phpbu\App\Exception |
||
285 | */ |
||
286 | private function validateSetup() |
||
295 | |||
296 | /** |
||
297 | * Return true if a given compression is valid false otherwise. |
||
298 | * |
||
299 | * @param string $compression |
||
300 | * @return bool |
||
301 | */ |
||
302 | public static function isCompressionValid(string $compression) : bool |
||
306 | } |
||
307 |