1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-08-27 08:54:25 +02:00

Added a new option for extracting unix symlinks.

Added new parameter to get the list of extracted files.
This commit is contained in:
Ne-Lexa
2020-01-22 12:49:45 +03:00
parent 47161bdb02
commit 8dcde47072
6 changed files with 201 additions and 65 deletions

View File

@@ -43,9 +43,10 @@ final class FilesUtil
\RecursiveIteratorIterator::CHILD_FIRST
);
/** @var \SplFileInfo $fileInfo */
foreach ($files as $fileInfo) {
$function = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
$function($fileInfo->getRealPath());
$function($fileInfo->getPathname());
}
rmdir($dir);
}
@@ -303,36 +304,19 @@ final class FilesUtil
}
/**
* @param string $linkPath
* @param string $target
* @param string $path
* @param bool $allowSymlink
*
* @return bool
*/
public static function symlink($target, $linkPath)
public static function symlink($target, $path, $allowSymlink)
{
if (\DIRECTORY_SEPARATOR === '\\') {
$linkPath = str_replace('/', '\\', $linkPath);
$target = str_replace('/', '\\', $target);
$abs = null;
if (!self::isAbsolutePath($target)) {
$abs = realpath(\dirname($linkPath) . \DIRECTORY_SEPARATOR . $target);
if (\is_string($abs)) {
$target = $abs;
}
}
if (\DIRECTORY_SEPARATOR === '\\' || !$allowSymlink) {
return file_put_contents($path, $target) !== false;
}
if (!symlink($target, $linkPath)) {
if (\DIRECTORY_SEPARATOR === '\\' && is_file($target)) {
return copy($target, $linkPath);
}
return false;
}
return true;
return symlink($target, $path);
}
/**