mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 16:07:03 +03:00
Improved Zip::addRecursive
This commit is contained in:
parent
086f5ebb06
commit
5effa242ae
1 changed files with 5 additions and 2 deletions
|
|
@ -200,11 +200,14 @@ class ZIP
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRecursive($dir, $ignore = '#/(\\.hg(/|$)|\\.hgignore)#') : void
|
public function addRecursive(string $dir, string $target_dir = '', string $ignore = '#/(\\.hg(/|$)|\\.hgignore)#') : void
|
||||||
{
|
{
|
||||||
\clearstatcache();
|
\clearstatcache();
|
||||||
$dir = \rtrim($dir,'\\/') . '/';
|
$dir = \rtrim($dir,'\\/') . '/';
|
||||||
$dirl = \strlen($dir);
|
$dirl = \strlen($dir);
|
||||||
|
if ($target_dir) {
|
||||||
|
$target_dir = \rtrim($target_dir,'\\/') . '/';
|
||||||
|
}
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \RecursiveIteratorIterator(
|
||||||
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS /*| \FilesystemIterator::FOLLOW_SYMLINKS*/),
|
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS /*| \FilesystemIterator::FOLLOW_SYMLINKS*/),
|
||||||
\RecursiveIteratorIterator::SELF_FIRST,
|
\RecursiveIteratorIterator::SELF_FIRST,
|
||||||
|
|
@ -215,7 +218,7 @@ class ZIP
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!$ignore || !\preg_match($ignore, $name)) {
|
if (!$ignore || !\preg_match($ignore, $name)) {
|
||||||
$this->addFile($name, \substr($name, $dirl));
|
$this->addFile($name, $target_dir . \substr($name, $dirl));
|
||||||
}
|
}
|
||||||
// like: tar --exclude-caches -czf file.tgz *
|
// like: tar --exclude-caches -czf file.tgz *
|
||||||
if (\strpos($name, 'CACHEDIR.TAG')) {
|
if (\strpos($name, 'CACHEDIR.TAG')) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue