1
0
Fork 0

Fix output when loading zips from cache, fixes #7498

pull/7515/head
Jordi Boggiano 2018-08-03 14:06:31 +02:00
parent a53b3c6b66
commit 73f14c0c7c
1 changed files with 20 additions and 13 deletions

View File

@ -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,7 +296,9 @@ 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;
try {
$this->download($package, $targetDir.'_compare', false); $this->download($package, $targetDir.'_compare', false);
$comparer = new Comparer(); $comparer = new Comparer();
@ -306,10 +307,16 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$comparer->doCompare(); $comparer->doCompare();
$output = $comparer->getChanged(true, true); $output = $comparer->getChanged(true, true);
$this->filesystem->removeDirectory($targetDir.'_compare'); $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);
} }
} }