1
0
Fork 0

Retry file downloads 3 times before giving up in case of basic network failure

pull/1837/merge
Jordi Boggiano 2013-05-03 12:29:18 +02:00
parent b4ff2032cf
commit 4b26c627ff
2 changed files with 22 additions and 4 deletions

View File

@ -95,10 +95,28 @@ class FileDownloader implements DownloaderInterface
try {
try {
if (!$this->cache || !$this->cache->copyTo($this->getCacheKey($package), $fileName)) {
$this->rfs->copy($hostname, $processedUrl, $fileName, $this->outputProgress);
if (!$this->outputProgress) {
$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) {
$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>)");
if (!$this->filesystem->removeDirectory($path)) {
// 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.');
}
}

View File

@ -539,7 +539,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
$json = $this->rfs->getContents($filename, $filename, false);
if ($sha256 && $sha256 !== hash('sha256', $json)) {
if ($retries) {
usleep(100);
usleep(100000);
continue;
}
@ -553,7 +553,7 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
break;
} catch (\Exception $e) {
if ($retries) {
usleep(100);
usleep(100000);
continue;
}