Skip to content

Commit

Permalink
Fix deletion of corrupt 0-bytes zip archives from the cache, fixes #1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 29, 2022
1 parent dca0a65 commit 757285e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Composer/Downloader/ArchiveDownloader.php
Expand Up @@ -120,7 +120,9 @@ public function install(PackageInterface $package, $path, $output = true)
}

return $promise->then(function () use ($self, $package, $filesystem, $fileName, $temporaryDir, $path) {
$filesystem->unlink($fileName);
if (file_exists($fileName)) {
$filesystem->unlink($fileName);
}

/**
* Returns the folder content, excluding .DS_Store
Expand Down
5 changes: 4 additions & 1 deletion src/Composer/Downloader/ZipDownloader.php
Expand Up @@ -184,7 +184,8 @@ public function extractWithZipArchive(PackageInterface $package, $file, $path)
$zipArchive = $this->zipArchiveObject ?: new ZipArchive();

try {
if (true === ($retval = $zipArchive->open($file))) {
$retval = -1;
if (file_exists($file) && filesize($file) > 0 && true === ($retval = $zipArchive->open($file))) {
$extractResult = $zipArchive->extractTo($path);

if (true === $extractResult) {
Expand Down Expand Up @@ -251,6 +252,8 @@ protected function getErrorMessage($retval, $file)
return sprintf("Zip read error (%s)", $file);
case ZipArchive::ER_SEEK:
return sprintf("Zip seek error (%s)", $file);
case -1:
return sprintf("'%s' is a corrupted zip archive (0 bytes), try again.", $file);
default:
return sprintf("'%s' is not a valid zip archive, got error code: %s", $file, $retval);
}
Expand Down

0 comments on commit 757285e

Please sign in to comment.