mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03: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
|
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');
|
$fp = \gzopen($this->filename, 'rb');
|
||||||
if (!$fp) {
|
if (!$fp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($files) {
|
||||||
|
$files = '/^(' . \implode('|', \array_map('preg_quote', \is_array($files) ? $files : [$files])) . ')/u';
|
||||||
|
}
|
||||||
|
|
||||||
\clearstatcache(false);
|
\clearstatcache(false);
|
||||||
\clearstatcache(true);
|
\clearstatcache(true);
|
||||||
while (!\gzeof($fp)) {
|
while (!\gzeof($fp)) {
|
||||||
|
|
@ -65,7 +64,13 @@ class TAR
|
||||||
if (\preg_match('#(^|/)PaxHeader/#', $header['filename'])) {
|
if (\preg_match('#(^|/)PaxHeader/#', $header['filename'])) {
|
||||||
} else if (\substr($header['filename'], -1) !== '/') {
|
} else if (\substr($header['filename'], -1) !== '/') {
|
||||||
$filename = ($header['path'] ? $header['path'] . '/' : '') . $header['filename'];
|
$filename = ($header['path'] ? $header['path'] . '/' : '') . $header['filename'];
|
||||||
|
if ($files && !\preg_match($files, $filename)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$filename = $directory . '/' . $filename;
|
$filename = $directory . '/' . $filename;
|
||||||
|
if (\is_file($filename) && !$overwrite) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$dir = \dirname($filename);
|
$dir = \dirname($filename);
|
||||||
if (!\is_dir($dir) && !\mkdir($dir, 0777, true)) {
|
if (!\is_dir($dir) && !\mkdir($dir, 0777, true)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue