* handle errors with ZipArchive error constants to get meaningful error messages
parent
30cfb69739
commit
aef502aa86
src/Composer/Downloader
|
@ -46,10 +46,38 @@ class ZipDownloader extends ArchiveDownloader
|
||||||
$zipArchive = new \ZipArchive();
|
$zipArchive = new \ZipArchive();
|
||||||
|
|
||||||
if (true !== ($retval = $zipArchive->open($file))) {
|
if (true !== ($retval = $zipArchive->open($file))) {
|
||||||
throw new \UnexpectedValueException($file.' is not a valid zip archive, got error code '.$retval);
|
$this->handleZipError($retval, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
$zipArchive->extractTo($path);
|
$zipArchive->extractTo($path);
|
||||||
$zipArchive->close();
|
$zipArchive->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function handleZipError($retval, $file)
|
||||||
|
{
|
||||||
|
switch ($retval) {
|
||||||
|
case \ZIPARCHIVE::ER_EXISTS:
|
||||||
|
throw new \UnexpectedValueException(sprintf("File '%s' already exists.", $file));
|
||||||
|
case \ZIPARCHIVE::ER_INCONS:
|
||||||
|
throw new \UnexpectedValueException(sprintf("Zip archive '%s' is inconsistent.", $file));
|
||||||
|
case \ZIPARCHIVE::ER_INVAL:
|
||||||
|
throw new \UnexpectedValueException(sprintf("Invalid argument. (%s)", $file));
|
||||||
|
case \ZIPARCHIVE::ER_MEMORY:
|
||||||
|
throw new \UnexpectedValueException(sprintf("Malloc failure. (%s)", $file));
|
||||||
|
case \ZIPARCHIVE::ER_NOENT:
|
||||||
|
throw new \UnexpectedValueException(sprintf("No such file: '%s'", $file));
|
||||||
|
case \ZIPARCHIVE::ER_NOZIP:
|
||||||
|
throw new \UnexpectedValueException(sprintf("'%s' is not a zip archive.", $file));
|
||||||
|
case \ZIPARCHIVE::ER_OPEN:
|
||||||
|
throw new \UnexpectedValueException(sprintf("Can't open file: %s", $file));
|
||||||
|
case \ZIPARCHIVE::ER_READ:
|
||||||
|
throw new \UnexpectedValueException(sprintf("Read error. (%s)", $file));
|
||||||
|
case \ZIPARCHIVE::ER_SEEK:
|
||||||
|
throw new \UnexpectedValueException(sprintf("Seek error. (%s)", $file));
|
||||||
|
default:
|
||||||
|
throw new \UnexpectedValueException(
|
||||||
|
sprintf("'%s' is not a valid zip archive, got error code: %s", $file, $retval)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue