From ddd7920d2af3452693ad1f2850736d4bdd0ffa6b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 17 Aug 2021 16:49:36 +0200 Subject: [PATCH] Fix corrupt archives in cache from getting the installs stuck forever, and make sure it fails only once, fixes #10028 --- src/Composer/Downloader/FileDownloader.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 0062d22b8a30..95a634a376bc 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -168,6 +168,12 @@ public function download(PackageInterface $package, $path, PackageInterface $pre if ($output) { $io->writeError(" - Loading " . $package->getName() . " (" . $package->getFullPrettyVersion() . ") from cache", true, IOInterface::VERY_VERBOSE); } + // mark the file as having been written in cache even though it is only read from cache, so that if + // the cache is corrupt the archive will be deleted and the next attempt will re-download it + // see https://github.com/composer/composer/issues/10028 + if (!$cache->isReadOnly()) { + $this->lastCacheWrites[$package->getName()] = $cacheKey; + } $result = \React\Promise\resolve($fileName); } else { if ($output) {