فهرست منبع

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

Jordi Boggiano 11 سال پیش
والد
کامیت
81994f6b90
1فایلهای تغییر یافته به همراه6 افزوده شده و 3 حذف شده
  1. 6 3
      src/Composer/Downloader/FileDownloader.php

+ 6 - 3
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.')');
             }