Skip to content

Commit

Permalink
Update .gitignore and fix Windows path issue in SevenZipProcess and B…
Browse files Browse the repository at this point in the history
…aseArchive
  • Loading branch information
ewilan-riviere committed Mar 8, 2024
1 parent 342a555 commit 9a77cbe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ vendor
example
temp
CHANGELOG-draft.md
.phpunit.cache
13 changes: 1 addition & 12 deletions src/Processes/SevenZipProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/Readers/BaseArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/ArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down

0 comments on commit 9a77cbe

Please sign in to comment.