Fix up merged code
parent
9922301841
commit
1cd07e1a2c
|
@ -15,6 +15,7 @@ namespace Composer\Downloader;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
|
use ZipArchive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
@ -43,10 +44,10 @@ class ZipDownloader extends ArchiveDownloader
|
||||||
throw new \RuntimeException('You need the zip extension enabled to use the ZipDownloader');
|
throw new \RuntimeException('You need the zip extension enabled to use the ZipDownloader');
|
||||||
}
|
}
|
||||||
|
|
||||||
$zipArchive = new \ZipArchive();
|
$zipArchive = new ZipArchive();
|
||||||
|
|
||||||
if (true !== ($retval = $zipArchive->open($file))) {
|
if (true !== ($retval = $zipArchive->open($file))) {
|
||||||
$this->handleZipError($retval, $file);
|
throw new \UnexpectedValueException($this->getErrorMessage($retval, $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
$zipArchive->extractTo($path);
|
$zipArchive->extractTo($path);
|
||||||
|
@ -54,38 +55,35 @@ class ZipDownloader extends ArchiveDownloader
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the error and give a meaningful error message to the user.
|
* Give a meaningful error message to the user.
|
||||||
*
|
*
|
||||||
* @param int $retval
|
* @param int $retval
|
||||||
* @param string $file
|
* @param string $file
|
||||||
*
|
* @return string
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
*/
|
*/
|
||||||
protected function handleZipError($retval, $file)
|
protected function getErrorMessage($retval, $file)
|
||||||
{
|
{
|
||||||
switch ($retval) {
|
switch ($retval) {
|
||||||
case \ZIPARCHIVE::ER_EXISTS:
|
case ZipArchive::ER_EXISTS:
|
||||||
throw new \UnexpectedValueException(sprintf("File '%s' already exists.", $file));
|
return sprintf("File '%s' already exists.", $file);
|
||||||
case \ZIPARCHIVE::ER_INCONS:
|
case ZipArchive::ER_INCONS:
|
||||||
throw new \UnexpectedValueException(sprintf("Zip archive '%s' is inconsistent.", $file));
|
return sprintf("Zip archive '%s' is inconsistent.", $file);
|
||||||
case \ZIPARCHIVE::ER_INVAL:
|
case ZipArchive::ER_INVAL:
|
||||||
throw new \UnexpectedValueException(sprintf("Invalid argument. (%s)", $file));
|
return sprintf("Invalid argument (%s)", $file);
|
||||||
case \ZIPARCHIVE::ER_MEMORY:
|
case ZipArchive::ER_MEMORY:
|
||||||
throw new \UnexpectedValueException(sprintf("Malloc failure. (%s)", $file));
|
return sprintf("Malloc failure (%s)", $file);
|
||||||
case \ZIPARCHIVE::ER_NOENT:
|
case ZipArchive::ER_NOENT:
|
||||||
throw new \UnexpectedValueException(sprintf("No such file: '%s'", $file));
|
return sprintf("No such zip file: '%s'", $file);
|
||||||
case \ZIPARCHIVE::ER_NOZIP:
|
case ZipArchive::ER_NOZIP:
|
||||||
throw new \UnexpectedValueException(sprintf("'%s' is not a zip archive.", $file));
|
return sprintf("'%s' is not a zip archive.", $file);
|
||||||
case \ZIPARCHIVE::ER_OPEN:
|
case ZipArchive::ER_OPEN:
|
||||||
throw new \UnexpectedValueException(sprintf("Can't open file: %s", $file));
|
return sprintf("Can't open zip file: %s", $file);
|
||||||
case \ZIPARCHIVE::ER_READ:
|
case ZipArchive::ER_READ:
|
||||||
throw new \UnexpectedValueException(sprintf("Read error. (%s)", $file));
|
return sprintf("Zip read error (%s)", $file);
|
||||||
case \ZIPARCHIVE::ER_SEEK:
|
case ZipArchive::ER_SEEK:
|
||||||
throw new \UnexpectedValueException(sprintf("Seek error. (%s)", $file));
|
return sprintf("Zip seek error (%s)", $file);
|
||||||
default:
|
default:
|
||||||
throw new \UnexpectedValueException(
|
return sprintf("'%s' is not a valid zip archive, got error code: %s", $file, $retval);
|
||||||
sprintf("'%s' is not a valid zip archive, got error code: %s", $file, $retval)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue