pull/2138/merge
parent
12d63b0a35
commit
7912253df6
|
@ -28,6 +28,9 @@ abstract class ArchiveDownloader extends FileDownloader
|
|||
*/
|
||||
public function download(PackageInterface $package, $path)
|
||||
{
|
||||
$temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8);
|
||||
$retries = 3;
|
||||
while ($retries--) {
|
||||
parent::download($package, $path);
|
||||
|
||||
$fileName = $this->getFileName($package, $path);
|
||||
|
@ -35,7 +38,6 @@ abstract class ArchiveDownloader extends FileDownloader
|
|||
$this->io->write(' Extracting archive');
|
||||
}
|
||||
|
||||
$temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8);
|
||||
try {
|
||||
$this->filesystem->ensureDirectoryExists($temporaryDir);
|
||||
try {
|
||||
|
@ -66,9 +68,22 @@ abstract class ArchiveDownloader extends FileDownloader
|
|||
// clean up
|
||||
$this->filesystem->removeDirectory($path);
|
||||
$this->filesystem->removeDirectory($temporaryDir);
|
||||
|
||||
// retry downloading if we have an invalid zip file
|
||||
if ($retries && $e instanceof \UnexpectedValueException && $e->getCode() === \ZipArchive::ER_NOZIP) {
|
||||
if ($this->io->isVerbose()) {
|
||||
$this->io->write(' Invalid zip file, retrying...');
|
||||
}
|
||||
usleep(500000);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$this->io->write('');
|
||||
}
|
||||
|
||||
|
|
|
@ -68,11 +68,7 @@ class ZipDownloader extends ArchiveDownloader
|
|||
$zipArchive = new ZipArchive();
|
||||
|
||||
if (true !== ($retval = $zipArchive->open($file))) {
|
||||
if (ZipArchive::ER_NOZIP === $retval) {
|
||||
@copy($file, $copy = sys_get_temp_dir().'/composer-zip-debug.zip');
|
||||
throw new \UnexpectedValueException($this->getErrorMessage($retval, $file).' filesize: '.filesize($file).', file copied to '.$copy.' for debugging, please report this and email us the file if possible');
|
||||
}
|
||||
throw new \UnexpectedValueException($this->getErrorMessage($retval, $file));
|
||||
throw new \UnexpectedValueException($this->getErrorMessage($retval, $file), $retval);
|
||||
}
|
||||
|
||||
if (true !== $zipArchive->extractTo($path)) {
|
||||
|
|
|
@ -33,7 +33,7 @@ class ZipDownloaderTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$io = $this->getMock('Composer\IO\IOInterface');
|
||||
$config = $this->getMock('Composer\Config');
|
||||
$config->expects($this->once())
|
||||
$config->expects($this->any())
|
||||
->method('get')
|
||||
->with('vendor-dir')
|
||||
->will($this->returnValue(sys_get_temp_dir().'/composer-zip-test-vendor'));
|
||||
|
|
Loading…
Reference in New Issue