From 0df18d08e18f8595ad8f17e8a1b93e32dd446bf7 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 27 Sep 2021 23:36:14 +0200 Subject: [PATCH] fix archives --- Utils/IO/Zip/Tar.php | 10 ++++++---- Utils/IO/Zip/Zip.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Utils/IO/Zip/Tar.php b/Utils/IO/Zip/Tar.php index 8459c31f7..2c5f3667b 100644 --- a/Utils/IO/Zip/Tar.php +++ b/Utils/IO/Zip/Tar.php @@ -34,12 +34,14 @@ class Tar implements ArchiveInterface public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool { $destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); - if (!$overwrite && \is_file($destination)) { + if ((!$overwrite && \is_file($destination)) + || \is_dir($destination) + ) { return false; } if (\is_string($sources)) { - $sources = [$sources]; + $sources = [$sources => '']; } $tar = new \PharData($destination); @@ -52,7 +54,7 @@ class Tar implements ArchiveInterface $source = $relative; } - $source = \str_replace('\\', '/', $source); + $source = FileUtils::absolute(\str_replace('\\', '/', $source)); $relative = \str_replace('\\', '/', $relative); if (\is_dir($source)) { @@ -73,7 +75,7 @@ class Tar implements ArchiveInterface $absolute = \realpath($file); $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)) { $tar->addEmptyDir($dir . '/'); diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index 6e411b287..1efa19ddd 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -34,7 +34,7 @@ class Zip implements ArchiveInterface public static function pack(string | array $sources, string $destination, bool $overwrite = false) : bool { $destination = FileUtils::absolute(\str_replace('\\', '/', $destination)); - if (!$overwrite && \is_file($destination) + if ((!$overwrite && \is_file($destination)) || \is_dir($destination) ) { return false;