-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathTar.php
76 lines (68 loc) · 2.04 KB
/
Tar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Extended version of \Magento\Framework\Archive\Tar that supports filtering
*/
namespace Magento\Framework\Backup\Archive;
use Magento\Framework\Backup\Filesystem\Iterator\Filter;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
/**
* Class to work with tar archives
*/
class Tar extends \Magento\Framework\Archive\Tar
{
/**
* Filenames or filename parts that are used for filtering files
*
* @var array
*/
protected $_skipFiles = [];
/**
* Method same as it's parent but filters files using \Magento\Framework\Backup\Filesystem\Iterator\Filter
*
* @param bool $skipRoot
* @param bool $finalize
* @return void
*
* @see \Magento\Framework\Archive\Tar::_createTar()
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _createTar($skipRoot = false, $finalize = false)
{
$path = $this->_getCurrentFile();
$filesystemIterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS),
RecursiveIteratorIterator::SELF_FIRST
);
$iterator = new Filter(
$filesystemIterator,
$this->_skipFiles
);
foreach ($iterator as $item) {
// exclude symlinks to do not get duplicates after follow symlinks in RecursiveDirectoryIterator
if ($item->isLink()) {
continue;
}
$this->_setCurrentFile($item->getPathname());
$this->_packAndWriteCurrentFile();
}
if ($finalize) {
$this->_getWriter()->write(str_repeat("\0", self::TAR_BLOCK_SIZE * 12));
}
}
/**
* Set files that shouldn't be added to tarball
*
* @param array $skipFiles
* @return $this
*/
public function setSkipFiles(array $skipFiles)
{
$this->_skipFiles = $skipFiles;
return $this;
}
}