Skip to content

Commit

Permalink
Extract chromedriver regardless of position in archive (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
u01jmg3 authored Aug 21, 2024
1 parent 34a5e26 commit 8edbeff
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected function update($detect, $currentOs, $version)

$archive = $this->download($version, $os);

$binary = $this->extract($version, $archive);
$binary = $this->extract($archive);

$this->rename($binary, $os);
}
Expand Down Expand Up @@ -292,27 +292,28 @@ protected function download($version, $os)
/**
* Extract the ChromeDriver binary from the archive and delete the archive.
*
* @param string $version
* @param string $archive
* @return string
*/
protected function extract($version, $archive)
protected function extract($archive)
{
$zip = new ZipArchive();

$zip->open($archive);

$zip->extractTo($this->directory);
$binary = null;

if (version_compare($version, '115.0', '<')) {
$index = 0;
} elseif (version_compare($version, '127.0', '<')) {
$index = 1;
} else {
$index = 2;
}
for ($fileIndex = 0; $fileIndex < $zip->numFiles; $fileIndex++) {
$filename = $zip->getNameIndex($fileIndex);

$binary = $zip->getNameIndex($index);
if (Str::startsWith(basename($filename), 'chromedriver')) {
$binary = $filename;

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

break;
}
}

$zip->close();

Expand Down

0 comments on commit 8edbeff

Please sign in to comment.