From 9a77cbed28254d103c34dfd6d38765d5d44f0229 Mon Sep 17 00:00:00 2001 From: Ewilan Riviere Date: Fri, 8 Mar 2024 11:20:26 +0100 Subject: [PATCH] Update .gitignore and fix Windows path issue in SevenZipProcess and BaseArchive --- .gitignore | 1 + src/Processes/SevenZipProcess.php | 13 +------------ src/Readers/BaseArchive.php | 12 ++++++++++++ tests/ArchiveTest.php | 3 ++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 85f3c96..9985a12 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ vendor example temp CHANGELOG-draft.md +.phpunit.cache diff --git a/src/Processes/SevenZipProcess.php b/src/Processes/SevenZipProcess.php index 11239ce..2e692e3 100644 --- a/src/Processes/SevenZipProcess.php +++ b/src/Processes/SevenZipProcess.php @@ -43,11 +43,8 @@ public static function make(string $path, ?string $password = null, ?string $bin public static function test(bool $exception = true): bool { exec('7z', $output, $res); - // $process = new Process(['7z']); - // $process->run(); $isValid = $res === 0; - // $isValid = $process->isSuccessful(); // check if 7z is installed if (! $isValid) { @@ -82,25 +79,17 @@ public function execute(string $command, array $args): array } if ($this->binaryPath) { - + $command = $this->binaryPath; } $command = "{$command} ".implode(' ', $args); - // $process = new Process([$command, ...$args]); - // $process->run(); - - // if (! $process->isSuccessful()) { - // throw new ProcessFailedException($process); - // } - try { exec($command, $output, $res); } catch (\Throwable $th) { throw new \Error($th->getMessage()); } - // $output = explode(PHP_EOL, $output); array_unshift($output, ''); return $output; diff --git a/src/Readers/BaseArchive.php b/src/Readers/BaseArchive.php index 7634335..86f0ee5 100755 --- a/src/Readers/BaseArchive.php +++ b/src/Readers/BaseArchive.php @@ -175,12 +175,24 @@ public function getFileItems(): array */ public function getFileItem(string $path): ?ArchiveItem { + $original_path = $path; + if (PHP_OS_FAMILY === 'Windows') { + $path = str_replace('/', DIRECTORY_SEPARATOR, $path); + } + $files = array_filter($this->files, fn (ArchiveItem $item) => $item->getPath() === $path); if (count($files) > 0) { return reset($files); } + if (PHP_OS_FAMILY === 'Windows') { + $files = array_filter($this->files, fn (ArchiveItem $item) => $item->getPath() === $original_path); + if (count($files) > 0) { + return reset($files); + } + } + return null; } diff --git a/tests/ArchiveTest.php b/tests/ArchiveTest.php index bca3614..0b04ce5 100644 --- a/tests/ArchiveTest.php +++ b/tests/ArchiveTest.php @@ -160,7 +160,8 @@ function (Pest\Expectation $item) use ($ext) { it('can handle archive with binary path', function (string $path) { if (PHP_OS_FAMILY === 'Windows') { - $binary_path = 'C:\Users\runneradmin\scoop\shims\7z.EXE'; + $current_user = exec('echo %USERNAME%'); + $binary_path = "C:\\Users\\{$current_user}\\scoop\\apps\\7zip\\current\\7z.exe"; } else { $binary_path = '/opt/homebrew/bin/7z'; }