diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 318e73c6f..666c33e01 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -15,6 +15,7 @@ namespace Composer\Downloader; use Composer\Package\PackageInterface; use Symfony\Component\Finder\Finder; use Composer\IO\IOInterface; +use Composer\Exception\IrrecoverableDownloadException; /** * Base downloader for archives @@ -25,6 +26,16 @@ use Composer\IO\IOInterface; */ abstract class ArchiveDownloader extends FileDownloader { + public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true) + { + $res = parent::download($package, $path, $prevPackage, $output); + if (is_dir($path) && !$this->filesystem->isDirEmpty($path)) { + throw new IrrecoverableDownloadException('Expected empty path to extract '.$package.' into but directory exists: '.$path); + } + + return $res; + } + /** * {@inheritDoc} * @throws \RuntimeException @@ -40,7 +51,7 @@ abstract class ArchiveDownloader extends FileDownloader $this->filesystem->ensureDirectoryExists($path); if (!$this->filesystem->isDirEmpty($path)) { - throw new \RuntimeException('Expected empty path to extract '.$package.' into but directory exists: '.$path); + throw new \UnexpectedValueException('Expected empty path to extract '.$package.' into but directory exists: '.$path); } do { diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 2fcfdd392..45467eb4c 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -15,6 +15,7 @@ namespace Composer\Downloader; use Composer\Package\PackageInterface; use Composer\IO\IOInterface; use Composer\Util\Filesystem; +use Composer\Exception\IrrecoverableDownloadException; use React\Promise\PromiseInterface; /** @@ -195,7 +196,7 @@ class DownloadManager } $handleError = function ($e) use ($sources, $source, $package, $io, $download) { - if ($e instanceof \RuntimeException) { + if ($e instanceof \RuntimeException && !$e instanceof IrrecoverableDownloadException) { if (!$sources) { throw $e; }