Skip to content

Commit

Permalink
Extract chromedriver regardless of position in archive (#13)
Browse files Browse the repository at this point in the history
* Extract chromedriver regardless of position in archive

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: Alex Leahy <[email protected]>
  • Loading branch information
crynobone and aleahy authored Aug 13, 2024
1 parent cf55dd4 commit 2e7ecc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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
23 changes: 13 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,27 @@ 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++) {
/** @var string $filename */
$filename = $zip->getNameIndex($fileIndex);

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

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

break;
default:
$index = 2;
}
}

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

$zip->close();

unlink($archive);
Expand Down

0 comments on commit 2e7ecc1

Please sign in to comment.