|
|
@ -59,46 +59,73 @@ class ZipDownloader extends ArchiveDownloader
|
|
|
|
return parent::download($package, $path, $output);
|
|
|
|
return parent::download($package, $path, $output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/**
|
|
|
|
* extract $file to $path
|
|
|
|
* extract $file to $path with "unzip" command
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $file File to extract
|
|
|
|
* @param string $file File to extract
|
|
|
|
* @param string $path Path where to extract file
|
|
|
|
* @param string $path Path where to extract file
|
|
|
|
|
|
|
|
* @return bool True if succeed
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function extract($file, $path)
|
|
|
|
protected function extractWithUnzip($file, $path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$processError = null;
|
|
|
|
$processError = null;
|
|
|
|
|
|
|
|
$command = 'unzip -qq '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path);
|
|
|
|
|
|
|
|
if (!Platform::isWindows()) {
|
|
|
|
|
|
|
|
$command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (self::$hasSystemUnzip && !(class_exists('ZipArchive') && Platform::isWindows())) {
|
|
|
|
try {
|
|
|
|
$command = 'unzip -qq '.ProcessExecutor::escape($file).' -d '.ProcessExecutor::escape($path);
|
|
|
|
if (0 === $this->process->execute($command, $ignoredOutput)) {
|
|
|
|
if (!Platform::isWindows()) {
|
|
|
|
return TRUE;
|
|
|
|
$command .= ' && chmod -R u+w ' . ProcessExecutor::escape($path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (0 === $this->process->execute($command, $ignoredOutput)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
$processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new \RuntimeException($processError);
|
|
|
|
$processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput();
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
$processError = 'Failed to execute ' . $command . "\n\n" . $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw new \RuntimeException($processError);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* extract $file to $path with ZipArchive
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $file File to extract
|
|
|
|
|
|
|
|
* @param string $path Path where to extract file
|
|
|
|
|
|
|
|
* @return bool True if succeed
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function extractWithZipArchive($file, $path)
|
|
|
|
|
|
|
|
{
|
|
|
|
$zipArchive = new ZipArchive();
|
|
|
|
$zipArchive = new ZipArchive();
|
|
|
|
|
|
|
|
|
|
|
|
if (true !== ($retval = $zipArchive->open($file))) {
|
|
|
|
if (true !== ($retval = $zipArchive->open($file))) {
|
|
|
|
throw new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file)."\n".$processError), $retval);
|
|
|
|
throw new \UnexpectedValueException(rtrim($this->getErrorMessage($retval, $file)."\n"), $retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (true !== $zipArchive->extractTo($path)) {
|
|
|
|
if (true !== $zipArchive->extractTo($path)) {
|
|
|
|
throw new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n".$processError));
|
|
|
|
throw new \RuntimeException(rtrim("There was an error extracting the ZIP file, it is either corrupted or using an invalid format.\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$zipArchive->close();
|
|
|
|
$zipArchive->close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* extract $file to $path
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $file File to extract
|
|
|
|
|
|
|
|
* @param string $path Path where to extract file
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function extract($file, $path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (self::$hasSystemUnzip && !(class_exists('ZipArchive') && Platform::isWindows())) {
|
|
|
|
|
|
|
|
if ( $this->extractWithUnzip($file, $path) ) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->extractWithZipArchive($file, $path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|