Retry file downloads 3 times before giving up in case of basic network failure
parent
b4ff2032cf
commit
4b26c627ff
|
@ -95,10 +95,28 @@ class FileDownloader implements DownloaderInterface
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if (!$this->cache || !$this->cache->copyTo($this->getCacheKey($package), $fileName)) {
|
if (!$this->cache || !$this->cache->copyTo($this->getCacheKey($package), $fileName)) {
|
||||||
$this->rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress);
|
|
||||||
if (!$this->outputProgress) {
|
if (!$this->outputProgress) {
|
||||||
$this->io->write(' Downloading');
|
$this->io->write(' Downloading');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try to download 3 times then fail hard
|
||||||
|
$retries = 3;
|
||||||
|
while ($retries--) {
|
||||||
|
try {
|
||||||
|
$this->rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress);
|
||||||
|
break;
|
||||||
|
} catch (TransportException $e) {
|
||||||
|
// if we got an http response with a proper code, then requesting again will probably not help, abort
|
||||||
|
if (0 !== $e->getCode() || !$retries) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
if ($this->io->isVerbose()) {
|
||||||
|
$this->io->write(' Download failed, retrying...');
|
||||||
|
}
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->cache) {
|
if ($this->cache) {
|
||||||
$this->cache->copyFrom($this->getCacheKey($package), $fileName);
|
$this->cache->copyFrom($this->getCacheKey($package), $fileName);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +190,7 @@ class FileDownloader implements DownloaderInterface
|
||||||
$this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)");
|
$this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)");
|
||||||
if (!$this->filesystem->removeDirectory($path)) {
|
if (!$this->filesystem->removeDirectory($path)) {
|
||||||
// retry after a bit on windows since it tends to be touchy with mass removals
|
// retry after a bit on windows since it tends to be touchy with mass removals
|
||||||
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250) && !$this->filesystem->removeDirectory($path))) {
|
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250000) && !$this->filesystem->removeDirectory($path))) {
|
||||||
throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
|
throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,7 +539,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
$json = $this->rfs->getContents($filename, $filename, false);
|
$json = $this->rfs->getContents($filename, $filename, false);
|
||||||
if ($sha256 && $sha256 !== hash('sha256', $json)) {
|
if ($sha256 && $sha256 !== hash('sha256', $json)) {
|
||||||
if ($retries) {
|
if ($retries) {
|
||||||
usleep(100);
|
usleep(100000);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
break;
|
break;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($retries) {
|
if ($retries) {
|
||||||
usleep(100);
|
usleep(100000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue