Re-download files when the cached copy is invalid, fixes #1496

main
Jordi Boggiano 11 years ago
parent a89eb9adea
commit 81994f6b90

@ -105,8 +105,12 @@ class FileDownloader implements DownloaderInterface
}
try {
$checksum = $package->getDistSha1Checksum();
$cacheKey = $this->getCacheKey($package);
try {
if (!$this->cache || !$this->cache->copyTo($this->getCacheKey($package), $fileName)) {
// download if we don't have it in cache or the cache is invalidated
if (!$this->cache || ($checksum && $checksum !== $this->cache->sha1($cacheKey)) || !$this->cache->copyTo($cacheKey, $fileName)) {
if (!$this->outputProgress) {
$this->io->write(' Downloading');
}
@ -130,7 +134,7 @@ class FileDownloader implements DownloaderInterface
}
if ($this->cache) {
$this->cache->copyFrom($this->getCacheKey($package), $fileName);
$this->cache->copyFrom($cacheKey, $fileName);
}
} else {
$this->io->write(' Loading from cache');
@ -158,7 +162,6 @@ class FileDownloader implements DownloaderInterface
.' directory is writable and you have internet connectivity');
}
$checksum = $package->getDistSha1Checksum();
if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
throw new \UnexpectedValueException('The checksum verification of the file failed (downloaded from '.$url.')');
}

Loading…
Cancel
Save