Rethrow download exceptions when no options left & clean up code
parent
1ccf4b0fc3
commit
31fd6c233c
|
@ -172,28 +172,25 @@ class DownloadManager
|
||||||
$sourceType = $package->getSourceType();
|
$sourceType = $package->getSourceType();
|
||||||
$distType = $package->getDistType();
|
$distType = $package->getDistType();
|
||||||
|
|
||||||
$wantDist = !$package->isDev() || $this->preferDist || !$sourceType;
|
$sources = array();
|
||||||
$wantSource = $preferSource && $sourceType;
|
|
||||||
|
|
||||||
$types = array();
|
|
||||||
if ($sourceType) {
|
if ($sourceType) {
|
||||||
$types[] = 'source';
|
$sources[] = 'source';
|
||||||
}
|
}
|
||||||
if ($distType) {
|
if ($distType) {
|
||||||
$types[] = 'dist';
|
$sources[] = 'dist';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($types)) {
|
if (empty($sources)) {
|
||||||
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
|
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($wantDist && !$wantSource) {
|
if ((!$package->isDev() || $this->preferDist) && !$preferSource) {
|
||||||
$types = array_reverse($types);
|
$sources = array_reverse($sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->filesystem->ensureDirectoryExists($targetDir);
|
$this->filesystem->ensureDirectoryExists($targetDir);
|
||||||
|
|
||||||
foreach ($types as $source) {
|
foreach ($sources as $i => $source) {
|
||||||
$package->setInstallationSource($source);
|
$package->setInstallationSource($source);
|
||||||
try {
|
try {
|
||||||
$downloader = $this->getDownloaderForInstalledPackage($package);
|
$downloader = $this->getDownloaderForInstalledPackage($package);
|
||||||
|
@ -202,13 +199,16 @@ class DownloadManager
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
|
if ($i == count($sources) - 1) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
$this->io->write(
|
$this->io->write(
|
||||||
'<warning>Caught an exception while trying to download '.
|
'<warning>Caught an exception while trying to download '.
|
||||||
$package->getPrettyString().
|
$package->getPrettyString().
|
||||||
': '.
|
': '.
|
||||||
$e->getMessage().'</warning>'
|
$e->getMessage().'</warning>'
|
||||||
);
|
);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue