Skip to content

Commit

Permalink
hasCache check
Browse files Browse the repository at this point in the history
  • Loading branch information
justafish committed Apr 12, 2024
1 parent a8e6b9d commit 46d6bac
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/BinaryInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,11 @@ protected function installBinary($binary, $version, $url, $sha, $hashalgo = 'sha
$httpDownloader = Factory::createHttpDownloader($this->io, $this->config);
$parts = explode('/', $url);
$fileName = array_pop($parts);
$cacheFolder = $this->cache->getRoot() . $binary . \DIRECTORY_SEPARATOR . $version;
if (empty($this->cache) || !($this->cache instanceof Cache) || !$this->cache->isEnabled()) {
$hasCache = !empty($this->cache) && $this->cache instanceof Cache) && $this->cache->isEnabled();
if ($hasCache) {
$cacheFolder = $this->cache->getRoot() . $binary . \DIRECTORY_SEPARATOR . $version;
}
else {
$cacheFolder = sys_get_temp_dir() . \DIRECTORY_SEPARATOR . $binary . \DIRECTORY_SEPARATOR . $version;
}
$cacheDestination = $cacheFolder . \DIRECTORY_SEPARATOR . $fileName;
Expand All @@ -208,7 +211,7 @@ protected function installBinary($binary, $version, $url, $sha, $hashalgo = 'sha

// Check the cache.
$fs->ensureDirectoryExists($cacheFolder);
if (!$this->cache->isEnabled() || !file_exists($cacheDestination) || (file_exists($cacheDestination) && hash_file($hashalgo, $cacheDestination) !== $sha)) {
if (!$hasCache || !file_exists($cacheDestination) || (file_exists($cacheDestination) && hash_file($hashalgo, $cacheDestination) !== $sha)) {
// Fetch a new copy of the binary.
$httpDownloader->copy($url, $cacheDestination);
} else {
Expand Down

0 comments on commit 46d6bac

Please sign in to comment.