Skip to content

Commit

Permalink
Extract chromedriver regardless of position in archive
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
aleahy authored and crynobone committed Aug 13, 2024
1 parent e6e54f9 commit 8f33b87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ jobs:
- '8.0'
- 8.1
- 8.2
- 8.3
dependencies:
- "highest"
- "lowest"
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"composer-runtime-api": "^2.2",
"composer/semver": "^1.5 || ^3.0",
"guzzlehttp/guzzle": "^7.2",
"illuminate/support": ">=5.7.0",
"symfony/console": "^4.3.4 || ^5.0 || ^6.0",
"symfony/polyfill-ctype": "^1.9",
"symfony/process": "^4.3.4 || ^5.0 || ^6.0"
Expand Down
22 changes: 12 additions & 10 deletions src/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Orchestra\DuskUpdater;

use Exception;
use Illuminate\Support\Str;
use RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -91,25 +92,26 @@ protected function extract(string $version, string $archive): string
throw new RuntimeException("Unable to extract {$archive} without --install-dir");
}

$binary = null;

$zip = new ZipArchive();

$zip->open($archive);

$zip->extractTo($this->directory);

switch (true) {
case version_compare($version, '115.0', '<'):
$index = 0;
break;
case version_compare($version, '127.0', '<'):
$index = 1;
for ($fileIndex = 0; $fileIndex < $zip->numFiles; $fileIndex++) {
$filename = $zip->getNameIndex($fileIndex);

if (Str::startsWith(basename($filename), 'chromedriver')) {

Check failure on line 106 in src/UpdateCommand.php

View workflow job for this annotation

GitHub Actions / PHP8.1 on ubuntu-latest (locked)

Parameter #1 $path of function basename expects string, string|false given.

Check failure on line 106 in src/UpdateCommand.php

View workflow job for this annotation

GitHub Actions / PHP8.1 on ubuntu-latest (locked)

Parameter #1 $path of function basename expects string, string|false given.
$binary = $filename;

$zip->extractTo($this->directory, $binary);

Check failure on line 109 in src/UpdateCommand.php

View workflow job for this annotation

GitHub Actions / PHP8.1 on ubuntu-latest (locked)

Parameter #2 $files of method ZipArchive::extractTo() expects array<string>|string|null, string|false given.

Check failure on line 109 in src/UpdateCommand.php

View workflow job for this annotation

GitHub Actions / PHP8.1 on ubuntu-latest (locked)

Parameter #2 $files of method ZipArchive::extractTo() expects array<string>|string|null, string|false given.

break;
default:
$index = 2;
}
}

$binary = $zip->getNameIndex($index);

$zip->close();

unlink($archive);
Expand Down

0 comments on commit 8f33b87

Please sign in to comment.