fix archives

This commit is contained in:
Dennis Eichhorn 2021-09-27 23:36:14 +02:00
parent 82fd468519
commit 0df18d08e1
2 changed files with 7 additions and 5 deletions

View File

@ -34,12 +34,14 @@ class Tar implements ArchiveInterface
public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool
{ {
$destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); $destination = FileUtils::absolute(\str_replace('\\', '/', $destination));
if (!$overwrite && \is_file($destination)) { if ((!$overwrite && \is_file($destination))
|| \is_dir($destination)
) {
return false; return false;
} }
if (\is_string($sources)) { if (\is_string($sources)) {
$sources = [$sources]; $sources = [$sources => ''];
} }
$tar = new \PharData($destination); $tar = new \PharData($destination);
@ -52,7 +54,7 @@ class Tar implements ArchiveInterface
$source = $relative; $source = $relative;
} }
$source = \str_replace('\\', '/', $source); $source = FileUtils::absolute(\str_replace('\\', '/', $source));
$relative = \str_replace('\\', '/', $relative); $relative = \str_replace('\\', '/', $relative);
if (\is_dir($source)) { if (\is_dir($source)) {
@ -73,7 +75,7 @@ class Tar implements ArchiveInterface
$absolute = \realpath($file); $absolute = \realpath($file);
$absolute = \str_replace('\\', '/', (string) $absolute); $absolute = \str_replace('\\', '/', (string) $absolute);
$dir = \rtrim($relative, '/\\') . '/' . \ltrim(\str_replace($source . '/', '', $absolute), '/\\'); $dir = \ltrim(\rtrim($relative, '/\\') . '/' . \ltrim(\str_replace($source . '/', '', $absolute), '/\\'), '/\\');
if (\is_dir($absolute)) { if (\is_dir($absolute)) {
$tar->addEmptyDir($dir . '/'); $tar->addEmptyDir($dir . '/');

View File

@ -34,7 +34,7 @@ class Zip implements ArchiveInterface
public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool
{ {
$destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); $destination = FileUtils::absolute(\str_replace('\\', '/', $destination));
if (!$overwrite && \is_file($destination) if ((!$overwrite && \is_file($destination))
|| \is_dir($destination) || \is_dir($destination)
) { ) {
return false; return false;