Fix FileDownloader::update impl to handle promises

main
Jordi Boggiano 4 years ago
parent 87a0fc5506
commit 9c78eda7db
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -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);
}
/**

@ -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 . " <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>): ", 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;
return $promise->then(function () use ($self, $target, $path, $io) {
$promise = $self->install($target, $path, false);
$io->writeError('');
$this->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');

@ -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);

@ -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}
*/

@ -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;

@ -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);

@ -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}
*/

@ -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;

Loading…
Cancel
Save