From aaef3ff5ff6827532f8ad9950c3971cc9236da93 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 17 Jun 2020 10:42:37 +0200 Subject: [PATCH] Improve error reporting when unzip fails due to race condition in unhandled Promise, refs #8988 --- src/Composer/Downloader/ZipDownloader.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index d891fb33b..83b904a8a 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -104,9 +104,15 @@ class ZipDownloader extends ArchiveDownloader throw $processError; } - $io->writeError(' '.$processError->getMessage().''); - $io->writeError(' The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)'); - $io->writeError(' Unzip with unzip command failed, falling back to ZipArchive class'); + if (!is_file($file)) { + $io->writeError(' '.$processError->getMessage().''); + $io->writeError(' This most likely is due to a custom installer plugin not handling the returned Promise from the downloader'); + $io->writeError(' See https://github.com/composer/installers/commit/5006d0c28730ade233a8f42ec31ac68fb1c5c9bb for an example fix'); + } else { + $io->writeError(' '.$processError->getMessage().''); + $io->writeError(' The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)'); + $io->writeError(' Unzip with unzip command failed, falling back to ZipArchive class'); + } return $self->extractWithZipArchive($package, $file, $path, true); }; @@ -114,9 +120,12 @@ class ZipDownloader extends ArchiveDownloader try { $promise = $this->process->executeAsync($command); - return $promise->then(function ($process) use ($tryFallback, $command, $package) { + return $promise->then(function ($process) use ($tryFallback, $command, $package, $file) { if (!$process->isSuccessful()) { - return $tryFallback(new \RuntimeException('Failed to extract '.$package->getName().': ('.$process->getExitCode().') '.$command."\n\n".$process->getErrorOutput())); + $output = $process->getErrorOutput(); + $output = str_replace(', '.$file.'.zip or '.$file.'.ZIP', '', $output); + + return $tryFallback(new \RuntimeException('Failed to extract '.$package->getName().': ('.$process->getExitCode().') '.$command."\n\n".$output)); } }); } catch (\Exception $e) {