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 | * Force local file resolution |
||
61 | * --force-local |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | private $local = false; |
||
66 | |||
67 | /** |
||
68 | * Ignore failed reads |
||
69 | * --ignore-failed-read |
||
70 | * |
||
71 | * @var bool |
||
72 | */ |
||
73 | private $ignoreFailedRead; |
||
74 | |||
75 | /** |
||
76 | * Should the source directory be removed. |
||
77 | * |
||
78 | * @var boolean |
||
79 | */ |
||
80 | private $removeSourceDir = false; |
||
81 | |||
82 | /** |
||
83 | * Limit data throughput |
||
84 | * | pv -L ${limit} |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | private $pvLimit = ''; |
||
89 | |||
90 | /** |
||
91 | * List of available compressors |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | private static $availableCompressions = [ |
||
96 | 'bzip2' => 'j', |
||
97 | 'gzip' => 'z', |
||
98 | 'xz' => 'J' |
||
99 | ]; |
||
100 | |||
101 | /** |
||
102 | * Instead of archiving symbolic links, archive the files they link to |
||
103 | * |
||
104 | * @var bool |
||
105 | */ |
||
106 | 34 | private $dereference = false; |
|
107 | |||
108 | 34 | /** |
|
109 | 34 | * Constructor. |
|
110 | * |
||
111 | * @param string $path |
||
112 | */ |
||
113 | public function __construct(string $path = '') |
||
117 | 13 | ||
118 | /** |
||
119 | 13 | * Return 'tar' compressor option e.g. 'j' for bzip2. |
|
120 | * |
||
121 | * @param string $compressor |
||
122 | * @return string |
||
123 | */ |
||
124 | protected function getCompressionOption(string $compressor) : string |
||
128 | 24 | ||
129 | /** |
||
130 | 24 | * Compress tar. |
|
131 | 13 | * |
|
132 | * @param string $compression |
||
133 | 24 | * @return \phpbu\App\Cli\Executable\Tar |
|
134 | */ |
||
135 | public function useCompression(string $compression) : Tar |
||
142 | 16 | ||
143 | /** |
||
144 | 16 | * Set compress program. |
|
145 | 16 | * |
|
146 | * @param string $program |
||
147 | * @return \phpbu\App\Cli\Executable\Tar |
||
148 | */ |
||
149 | public function useCompressProgram(string $program) : Tar |
||
154 | 2 | ||
155 | /** |
||
156 | 2 | * Add an path to exclude. |
|
157 | 2 | * |
|
158 | * @param string $path |
||
159 | * @return \phpbu\App\Cli\Executable\Tar |
||
160 | */ |
||
161 | public function addExclude(string $path) : Tar |
||
166 | 16 | ||
167 | /** |
||
168 | 16 | * Force local file resolution. |
|
169 | 16 | * |
|
170 | * @param bool $bool |
||
171 | * @return \phpbu\App\Cli\Executable\Tar |
||
172 | */ |
||
173 | public function forceLocal(bool $bool) : Tar |
||
178 | 16 | ||
179 | /** |
||
180 | 16 | * Ignore failed reads setter. |
|
181 | 16 | * |
|
182 | * @param bool $bool |
||
183 | * @return \phpbu\App\Cli\Executable\Tar |
||
184 | */ |
||
185 | public function ignoreFailedRead(bool $bool) : Tar |
||
190 | 17 | ||
191 | /** |
||
192 | 17 | * Limit the data throughput. |
|
193 | 17 | * |
|
194 | * @param string $limit |
||
195 | * @return \phpbu\App\Cli\Executable\Tar |
||
196 | */ |
||
197 | public function throttle(string $limit) : Tar |
||
202 | |||
203 | 4 | /** |
|
204 | * Does the tar handle the compression. |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function handlesCompression() : bool |
||
212 | |||
213 | 32 | /** |
|
214 | * Set folder to compress. |
||
215 | 32 | * |
|
216 | 31 | * @param string $path |
|
217 | 31 | * @return \phpbu\App\Cli\Executable\Tar |
|
218 | * @throws \phpbu\App\Exception |
||
219 | */ |
||
220 | public function archiveDirectory(string $path) : Tar |
||
226 | 30 | ||
227 | /** |
||
228 | 30 | * Set target filename. |
|
229 | 30 | * |
|
230 | * @param string $path |
||
231 | * @return \phpbu\App\Cli\Executable\Tar |
||
232 | */ |
||
233 | public function archiveTo(string $path) : Tar |
||
238 | 21 | ||
239 | /** |
||
240 | 21 | * Delete the source directory. |
|
241 | 21 | * |
|
242 | * @param boolean $bool |
||
243 | * @return \phpbu\App\Cli\Executable\Tar |
||
244 | */ |
||
245 | public function removeSourceDirectory(bool $bool) : Tar |
||
250 | 32 | ||
251 | /** |
||
252 | 32 | * Instead of archiving symbolic links, archive the files they link |
|
253 | * |
||
254 | 30 | * @param bool $bool |
|
255 | 30 | * @return \phpbu\App\Cli\Executable\Tar |
|
256 | 30 | */ |
|
257 | 30 | public function dereference(bool $bool) : Tar |
|
262 | 30 | ||
263 | 30 | /** |
|
264 | 30 | * Tar CommandLine generator. |
|
265 | * |
||
266 | 30 | * @return \SebastianFeldmann\Cli\CommandLine |
|
267 | 3 | * @throws \phpbu\App\Exception |
|
268 | 3 | */ |
|
269 | 3 | protected function createCommandLine() : CommandLine |
|
303 | |||
304 | 30 | /** |
|
305 | 3 | * Adds necessary exclude options to tat command. |
|
306 | 3 | * |
|
307 | * @param \SebastianFeldmann\Cli\Command\Executable $tar |
||
308 | 30 | */ |
|
309 | protected function setExcludeOptions(Cmd $tar) |
||
315 | 30 | ||
316 | /** |
||
317 | 30 | * Configure warning handling. |
|
318 | 7 | * With the 'ignoreFailedRead' option set, exit code '1' is also accepted since it only indicates a warning. |
|
319 | * |
||
320 | 30 | * @param \SebastianFeldmann\Cli\Command\Executable $tar |
|
321 | */ |
||
322 | protected function handleWarnings(Cmd $tar) |
||
329 | 7 | ||
330 | 7 | /** |
|
331 | 7 | * Add a remove command if requested. |
|
332 | * |
||
333 | * @param \SebastianFeldmann\Cli\CommandLine $process |
||
334 | */ |
||
335 | protected function addRemoveCommand(CommandLine $process) |
||
341 | |||
342 | 32 | /** |
|
343 | 1 | * Return 'rm' command. |
|
344 | * |
||
345 | 31 | * @return \SebastianFeldmann\Cli\Command\Executable |
|
346 | */ |
||
347 | protected function getRmCommand() : Cmd |
||
353 | |||
354 | 32 | /** |
|
355 | 1 | * Check directory to compress. |
|
356 | * |
||
357 | 31 | * @param string $path |
|
358 | 1 | * @throws \phpbu\App\Exception |
|
359 | */ |
||
360 | 30 | private function validateDirectory(string $path) |
|
366 | |||
367 | /** |
||
368 | 26 | * Check if source and target values are set. |
|
369 | * |
||
370 | 26 | * @throws \phpbu\App\Exception |
|
371 | */ |
||
372 | private function validateSetup() |
||
381 | |||
382 | /** |
||
383 | * Return true if a given compression is valid false otherwise. |
||
384 | * |
||
385 | * @param string $compression |
||
386 | * @return bool |
||
387 | */ |
||
388 | public static function isCompressionValid(string $compression) : bool |
||
392 | |||
393 | /** |
||
394 | * Should output be throttled through pv. |
||
395 | * |
||
396 | * @return bool |
||
397 | */ |
||
398 | public function isThrottled() : bool |
||
402 | } |
||
403 |