diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php
index bcee49f9a..d77d55738 100644
--- a/src/Composer/Downloader/ArchiveDownloader.php
+++ b/src/Composer/Downloader/ArchiveDownloader.php
@@ -29,14 +29,12 @@ abstract class ArchiveDownloader extends FileDownloader
{
public function download(PackageInterface $package, $path, PackageInterface $prevPackage = null, $output = true)
{
- $res = parent::download($package, $path, $prevPackage, $output);
-
// if not downgrading and the dir already exists it seems we have an inconsistent state in the vendor dir and the user should fix it
if (!$prevPackage && is_dir($path) && !$this->filesystem->isDirEmpty($path)) {
throw new IrrecoverableDownloadException('Expected empty path to extract '.$package.' into but directory exists: '.$path);
}
- return $res;
+ return parent::download($package, $path, $prevPackage, $output);
}
/**
diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php
index f5674cf90..5f88cf140 100644
--- a/src/Composer/Downloader/FileDownloader.php
+++ b/src/Composer/Downloader/FileDownloader.php
@@ -27,7 +27,9 @@ use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\Filesystem;
use Composer\Util\HttpDownloader;
use Composer\Util\Url as UrlUtil;
+use Composer\Util\ProcessExecutor;
use Composer\Downloader\TransportException;
+use React\Promise\PromiseInterface;
/**
* Base downloader for files
@@ -51,6 +53,8 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
protected $cache;
/** @var EventDispatcher */
protected $eventDispatcher;
+ /** @var ProcessExecutor */
+ protected $process;
/**
* @private this is only public for php 5.3 support in closures
*/
@@ -67,14 +71,15 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @param Cache $cache Cache instance
* @param Filesystem $filesystem The filesystem
*/
- public function __construct(IOInterface $io, Config $config, HttpDownloader $httpDownloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $filesystem = null)
+ public function __construct(IOInterface $io, Config $config, HttpDownloader $httpDownloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $filesystem = null, ProcessExecutor $process = null)
{
$this->io = $io;
$this->config = $config;
$this->eventDispatcher = $eventDispatcher;
$this->httpDownloader = $httpDownloader;
- $this->filesystem = $filesystem ?: new Filesystem();
$this->cache = $cache;
+ $this->process = $process ?: new ProcessExecutor($io);
+ $this->filesystem = $filesystem ?: new Filesystem($this->process);
if ($this->cache && $this->cache->gcIsNecessary()) {
$this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
@@ -333,10 +338,19 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$actionName = VersionParser::isUpgrade($initial->getVersion(), $target->getVersion()) ? 'Upgrading' : 'Downgrading';
$this->io->writeError(" - " . $actionName . " " . $name . " (" . $from . " => " . $to . "): ", false);
- $this->remove($initial, $path, false);
- $this->install($target, $path, false);
+ $promise = $this->remove($initial, $path, false);
+ if (!$promise instanceof PromiseInterface) {
+ $promise = \React\Promise\resolve();
+ }
+ $self = $this;
+ $io = $this->io;
- $this->io->writeError('');
+ return $promise->then(function () use ($self, $target, $path, $io) {
+ $promise = $self->install($target, $path, false);
+ $io->writeError('');
+
+ return $promise;
+ });
}
/**
@@ -410,9 +424,10 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$output = '';
try {
- $res = $this->download($package, $targetDir.'_compare', null, false);
+ $this->download($package, $targetDir.'_compare', null, false);
$this->httpDownloader->wait();
- $res = $this->install($package, $targetDir.'_compare', false);
+ $this->install($package, $targetDir.'_compare', false);
+ $this->process->wait();
$comparer = new Comparer();
$comparer->setSource($targetDir.'_compare');
diff --git a/src/Composer/Downloader/GzipDownloader.php b/src/Composer/Downloader/GzipDownloader.php
index 0b12b4380..3ebff597a 100644
--- a/src/Composer/Downloader/GzipDownloader.php
+++ b/src/Composer/Downloader/GzipDownloader.php
@@ -29,15 +29,6 @@ use Composer\Util\Filesystem;
*/
class GzipDownloader extends ArchiveDownloader
{
- /** @var ProcessExecutor */
- protected $process;
-
- public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $fs = null, ProcessExecutor $process = null)
- {
- $this->process = $process ?: new ProcessExecutor($io);
- parent::__construct($io, $config, $downloader, $eventDispatcher, $cache, $fs);
- }
-
protected function extract(PackageInterface $package, $file, $path)
{
$filename = pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_FILENAME);
diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php
index 51e9f7709..2cb74d641 100644
--- a/src/Composer/Downloader/PathDownloader.php
+++ b/src/Composer/Downloader/PathDownloader.php
@@ -39,15 +39,6 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
const STRATEGY_SYMLINK = 10;
const STRATEGY_MIRROR = 20;
- /** @var ProcessExecutor */
- private $process;
-
- public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $fs = null, ProcessExecutor $process = null)
- {
- $this->process = $process ?: new ProcessExecutor($io);
- parent::__construct($io, $config, $downloader, $eventDispatcher, $cache, $fs);
- }
-
/**
* {@inheritdoc}
*/
diff --git a/src/Composer/Downloader/RarDownloader.php b/src/Composer/Downloader/RarDownloader.php
index 0ca15de1f..b0484b661 100644
--- a/src/Composer/Downloader/RarDownloader.php
+++ b/src/Composer/Downloader/RarDownloader.php
@@ -33,15 +33,6 @@ use RarArchive;
*/
class RarDownloader extends ArchiveDownloader
{
- /** @var ProcessExecutor */
- protected $process;
-
- public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $fs = null, ProcessExecutor $process = null)
- {
- $this->process = $process ?: new ProcessExecutor($io);
- parent::__construct($io, $config, $downloader, $eventDispatcher, $cache, $fs);
- }
-
protected function extract(PackageInterface $package, $file, $path)
{
$processError = null;
diff --git a/src/Composer/Downloader/XzDownloader.php b/src/Composer/Downloader/XzDownloader.php
index 34956d997..b043af333 100644
--- a/src/Composer/Downloader/XzDownloader.php
+++ b/src/Composer/Downloader/XzDownloader.php
@@ -29,16 +29,6 @@ use Composer\Util\Filesystem;
*/
class XzDownloader extends ArchiveDownloader
{
- /** @var ProcessExecutor */
- protected $process;
-
- public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $fs = null, ProcessExecutor $process = null)
- {
- $this->process = $process ?: new ProcessExecutor($io);
-
- parent::__construct($io, $config, $downloader, $eventDispatcher, $cache, $fs);
- }
-
protected function extract(PackageInterface $package, $file, $path)
{
$command = 'tar -xJf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path);
diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php
index c5fd2b11b..d891fb33b 100644
--- a/src/Composer/Downloader/ZipDownloader.php
+++ b/src/Composer/Downloader/ZipDownloader.php
@@ -34,17 +34,9 @@ class ZipDownloader extends ArchiveDownloader
private static $hasZipArchive;
private static $isWindows;
- /** @var ProcessExecutor */
- protected $process;
/** @var ZipArchive|null */
private $zipArchiveObject;
- public function __construct(IOInterface $io, Config $config, HttpDownloader $downloader, EventDispatcher $eventDispatcher = null, Cache $cache = null, Filesystem $fs = null, ProcessExecutor $process = null)
- {
- $this->process = $process ?: new ProcessExecutor($io);
- parent::__construct($io, $config, $downloader, $eventDispatcher, $cache, $fs);
- }
-
/**
* {@inheritDoc}
*/
diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php
index 5bc41ee6b..509fa62b0 100644
--- a/src/Composer/Factory.php
+++ b/src/Composer/Factory.php
@@ -495,11 +495,11 @@ class Factory
$dm->setDownloader('perforce', new Downloader\PerforceDownloader($io, $config, $process, $fs));
$dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
$dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
- $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs));
+ $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
$dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
$dm->setDownloader('xz', new Downloader\XzDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
- $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs));
- $dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs));
+ $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
+ $dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
$dm->setDownloader('path', new Downloader\PathDownloader($io, $config, $httpDownloader, $eventDispatcher, $cache, $fs, $process));
return $dm;