mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-03-12 15:55:13 +08:00
SnappyMail\TAR::extractTo support the $files and $overwrite parameters
This commit is contained in:
parent
6e2e07ce98
commit
b1471c2bbd
1 changed files with 10 additions and 5 deletions
|
@ -23,16 +23,15 @@ class TAR
|
|||
*/
|
||||
public function extractTo(string $directory, $files = null, bool $overwrite = false) : bool
|
||||
{
|
||||
if ($files) {
|
||||
\trigger_error('$files parameter not yet supported');
|
||||
return false;
|
||||
}
|
||||
|
||||
$fp = \gzopen($this->filename, 'rb');
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($files) {
|
||||
$files = '/^(' . \implode('|', \array_map('preg_quote', \is_array($files) ? $files : [$files])) . ')/u';
|
||||
}
|
||||
|
||||
\clearstatcache(false);
|
||||
\clearstatcache(true);
|
||||
while (!\gzeof($fp)) {
|
||||
|
@ -65,7 +64,13 @@ class TAR
|
|||
if (\preg_match('#(^|/)PaxHeader/#', $header['filename'])) {
|
||||
} else if (\substr($header['filename'], -1) !== '/') {
|
||||
$filename = ($header['path'] ? $header['path'] . '/' : '') . $header['filename'];
|
||||
if ($files && !\preg_match($files, $filename)) {
|
||||
continue;
|
||||
}
|
||||
$filename = $directory . '/' . $filename;
|
||||
if (\is_file($filename) && !$overwrite) {
|
||||
continue;
|
||||
}
|
||||
$dir = \dirname($filename);
|
||||
if (!\is_dir($dir) && !\mkdir($dir, 0777, true)) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue