diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 9fa6a3338..abe1b6884 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -43,7 +43,7 @@ abstract class ArchiveDownloader extends FileDownloader $this->extract($fileName, $temporaryDir); } catch (\Exception $e) { // remove cache if the file was corrupted - parent::clearCache($package, $path); + parent::clearLastCacheWrite($package); throw $e; } diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index b7d9d2937..1a30fd71e 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -39,6 +39,7 @@ class FileDownloader implements DownloaderInterface protected $filesystem; protected $cache; protected $outputProgress = true; + private $lastCacheWrites = array(); /** * Constructor. @@ -147,6 +148,7 @@ class FileDownloader implements DownloaderInterface } if ($this->cache) { + $this->lastCacheWrites[$package->getName()] = $cacheKey; $this->cache->copyFrom($cacheKey, $fileName); } } else { @@ -164,7 +166,7 @@ class FileDownloader implements DownloaderInterface } catch (\Exception $e) { // clean up $this->filesystem->removeDirectory($path); - $this->clearCache($package, $path, $processedUrl); + $this->clearLastCacheWrite($package); throw $e; } @@ -181,10 +183,11 @@ class FileDownloader implements DownloaderInterface return $this; } - protected function clearCache(PackageInterface $package, $path, $processedUrl) + protected function clearLastCacheWrite(PackageInterface $package) { - if ($this->cache) { - $this->cache->remove($this->getCacheKey($package, $processedUrl)); + if ($this->cache && isset($this->lastCacheWrites[$package->getName()])) { + $this->cache->remove($this->lastCacheWrites[$package->getName()]); + unset($this->lastCacheWrites[$package->getName()]); } }