From 81994f6b90fb8a1380622710519c87bec19369e4 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 31 Dec 2013 17:28:27 +0100 Subject: [PATCH] Re-download files when the cached copy is invalid, fixes #1496 --- src/Composer/Downloader/FileDownloader.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 3399032c2..2f8c048dc 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -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.')'); }