Fix output when loading zips from cache, fixes #7498

main
Jordi Boggiano 6 years ago
parent a53b3c6b66
commit 73f14c0c7c

@ -137,8 +137,11 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$checksum = $package->getDistSha1Checksum(); $checksum = $package->getDistSha1Checksum();
$cacheKey = $this->getCacheKey($package, $processedUrl); $cacheKey = $this->getCacheKey($package, $processedUrl);
// download if we don't have it in cache or the cache is invalidated // use from cache if it is present and has a valid checksum or we have no checksum to check against
if (!$this->cache || ($checksum && $checksum !== $this->cache->sha1($cacheKey)) || !$this->cache->copyTo($cacheKey, $fileName)) { if ($this->cache && (!$checksum || $checksum === $this->cache->sha1($cacheKey)) && $this->cache->copyTo($cacheKey, $fileName)) {
$this->io->writeError('Loading from cache', false);
} else {
// download if cache restore failed
if (!$this->outputProgress) { if (!$this->outputProgress) {
$this->io->writeError('Downloading', false); $this->io->writeError('Downloading', false);
} }
@ -168,10 +171,6 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$this->lastCacheWrites[$package->getName()] = $cacheKey; $this->lastCacheWrites[$package->getName()] = $cacheKey;
$this->cache->copyFrom($cacheKey, $fileName); $this->cache->copyFrom($cacheKey, $fileName);
} }
} else {
if (!$this->outputProgress) {
$this->io->writeError('Loading from cache', false);
}
} }
if (!file_exists($fileName)) { if (!file_exists($fileName)) {
@ -297,19 +296,27 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$this->io = new NullIO; $this->io = new NullIO;
$this->io->loadConfiguration($this->config); $this->io->loadConfiguration($this->config);
$this->outputProgress = false; $this->outputProgress = false;
$e = null;
$this->download($package, $targetDir.'_compare', false); try {
$this->download($package, $targetDir.'_compare', false);
$comparer = new Comparer();
$comparer->setSource($targetDir.'_compare'); $comparer = new Comparer();
$comparer->setUpdate($targetDir); $comparer->setSource($targetDir.'_compare');
$comparer->doCompare(); $comparer->setUpdate($targetDir);
$output = $comparer->getChanged(true, true); $comparer->doCompare();
$this->filesystem->removeDirectory($targetDir.'_compare'); $output = $comparer->getChanged(true, true);
$this->filesystem->removeDirectory($targetDir.'_compare');
} catch (\Exception $e) {
}
$this->io = $prevIO; $this->io = $prevIO;
$this->outputProgress = $prevProgress; $this->outputProgress = $prevProgress;
if ($e) {
throw $e;
}
return trim($output); return trim($output);
} }
} }

Loading…
Cancel
Save