1
0
Fork 0

Fix ZipDownloader, fixes #221

pull/222/head
Jordi Boggiano 2012-01-18 16:37:55 +01:00
parent 405f876fa6
commit f5ac5b9b3e
1 changed files with 10 additions and 4 deletions

View File

@ -13,21 +13,27 @@
namespace Composer\Downloader; namespace Composer\Downloader;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Util\Process; use Composer\Util\ProcessExecutor;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
class ZipDownloader extends FileDownloader class ZipDownloader extends FileDownloader
{ {
protected $process;
public function __construct(ProcessExecutor $process = null)
{
$this->process = $process ?: new ProcessExecutor;
}
protected function extract($file, $path) protected function extract($file, $path)
{ {
if (!class_exists('ZipArchive')) { if (!class_exists('ZipArchive')) {
// try to use unzip on *nix // try to use unzip on *nix
if (!defined('PHP_WINDOWS_VERSION_BUILD')) { if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$process = new Process('unzip '.escapeshellarg($file).' -d '.escapeshellarg($path)); $result = $this->process->execute('unzip '.escapeshellarg($file).' -d '.escapeshellarg($path));
$process->run(); if (0 == $result) {
if ($process->isSuccessful()) {
return; return;
} }
} }