Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract chromedriver regardless of position in archive #13

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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