From b21bb1dcc5de19fe87f518eeab5e4ddf7c94daed Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Tue, 28 Aug 2012 22:27:25 +0200 Subject: [PATCH] Checks support before downloading the package --- .../Package/Archiver/ArchiveManager.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Composer/Package/Archiver/ArchiveManager.php b/src/Composer/Package/Archiver/ArchiveManager.php index 73d273505..f5123f7ef 100644 --- a/src/Composer/Package/Archiver/ArchiveManager.php +++ b/src/Composer/Package/Archiver/ArchiveManager.php @@ -68,6 +68,20 @@ class ArchiveManager throw new \InvalidArgumentException('Format must be specified'); } + $usableArchiver = null; + $sourceType = $package->getSourceType(); + + foreach ($this->archivers as $archiver) { + if ($archiver->supports($format, $package->getSourceType())) { + $usableArchiver = $archiver; + } + } + + // Checks the format/source type are supported before downloading the package + if (null === $usableArchiver) { + throw new \RuntimeException(sprintf('No archiver found to support %s format', $format)); + } + $filesystem = new Filesystem(); $packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName()); @@ -82,16 +96,7 @@ class ArchiveManager // Download sources $this->downloadManager->download($package, $sources, true); - $sourceType = $package->getSourceType(); - $sourceRef = $package->getSourceReference(); - foreach ($this->archivers as $archiver) { - if ($archiver->supports($format, $sourceType)) { - $archiver->archive($sources, $target, $format, $sourceRef); - - return $target; - } - } - - throw new \RuntimeException(sprintf('No archiver found to support %s format', $format)); + $sourceRef = $package->getSourceReference(); + $usableArchiver->archive($sources, $target, $format, $sourceRef); } }