1
0
Fork 0

Avoid doing too many loads of the remotefilesystem

pull/4759/head
Jordi Boggiano 2016-01-10 20:06:10 +00:00
parent fc4d94f160
commit c1cc6bfecf
9 changed files with 49 additions and 32 deletions

View File

@ -17,6 +17,7 @@ use Composer\Cache;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Package\PackageInterface;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Composer\IO\IOInterface;
/**
@ -28,10 +29,10 @@ class GzipDownloader extends ArchiveDownloader
{
protected $process;
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
{
$this->process = $process ?: new ProcessExecutor($io);
parent::__construct($io, $config, $eventDispatcher, $cache);
parent::__construct($io, $config, $eventDispatcher, $cache, $rfs);
}
protected function extract($file, $path)

View File

@ -16,6 +16,7 @@ use Composer\Config;
use Composer\Cache;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Composer\IO\IOInterface;
use RarArchive;
@ -30,10 +31,10 @@ class RarDownloader extends ArchiveDownloader
{
protected $process;
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
{
$this->process = $process ?: new ProcessExecutor($io);
parent::__construct($io, $config, $eventDispatcher, $cache);
parent::__construct($io, $config, $eventDispatcher, $cache, $rfs);
}
protected function extract($file, $path)

View File

@ -37,7 +37,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
$this->io = $io;
$this->config = $config;
$this->process = $process ?: new ProcessExecutor($io);
$this->filesystem = $fs ?: new Filesystem;
$this->filesystem = $fs ?: new Filesystem($this->process);
}
/**

View File

@ -17,6 +17,7 @@ use Composer\Cache;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Package\PackageInterface;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Composer\IO\IOInterface;
/**
@ -29,11 +30,11 @@ class XzDownloader extends ArchiveDownloader
{
protected $process;
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
{
$this->process = $process ?: new ProcessExecutor($io);
parent::__construct($io, $config, $eventDispatcher, $cache);
parent::__construct($io, $config, $eventDispatcher, $cache, $rfs);
}
protected function extract($file, $path)

View File

@ -16,6 +16,7 @@ use Composer\Config;
use Composer\Cache;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Composer\IO\IOInterface;
use ZipArchive;
@ -26,10 +27,10 @@ class ZipDownloader extends ArchiveDownloader
{
protected $process;
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null)
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null, RemoteFilesystem $rfs = null)
{
$this->process = $process ?: new ProcessExecutor($io);
parent::__construct($io, $config, $eventDispatcher, $cache);
parent::__construct($io, $config, $eventDispatcher, $cache, $rfs);
}
protected function extract($file, $path)

View File

@ -19,6 +19,7 @@ use Composer\Package\Archiver;
use Composer\Package\Version\VersionGuesser;
use Composer\Repository\RepositoryManager;
use Composer\Repository\WritableRepositoryInterface;
use Composer\Util\Filesystem;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
@ -162,7 +163,7 @@ class Factory
throw new \InvalidArgumentException('This function requires either an IOInterface or a RepositoryManager');
}
$factory = new static;
$rm = $factory->createRepositoryManager($io, $config);
$rm = $factory->createRepositoryManager($io, $config, null, self::createRemoteFilesystem($io, $config));
}
foreach ($config->getRepositories() as $index => $repo) {
@ -262,12 +263,14 @@ class Factory
$io->loadConfiguration($config);
}
$rfs = self::createRemoteFilesystem($io, $config);
// initialize event dispatcher
$dispatcher = new EventDispatcher($composer, $io);
$composer->setEventDispatcher($dispatcher);
// initialize repository manager
$rm = $this->createRepositoryManager($io, $config, $dispatcher);
$rm = $this->createRepositoryManager($io, $config, $dispatcher, $rfs);
$composer->setRepositoryManager($rm);
// load local repository
@ -292,7 +295,7 @@ class Factory
if ($fullLoad) {
// initialize download manager
$dm = $this->createDownloadManager($io, $config, $dispatcher);
$dm = $this->createDownloadManager($io, $config, $dispatcher, $rfs);
$composer->setDownloadManager($dm);
// initialize autoload generator
@ -336,9 +339,9 @@ class Factory
* @param EventDispatcher $eventDispatcher
* @return Repository\RepositoryManager
*/
protected function createRepositoryManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
protected function createRepositoryManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
{
$rm = new RepositoryManager($io, $config, $eventDispatcher);
$rm = new RepositoryManager($io, $config, $eventDispatcher, $rfs);
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
@ -391,7 +394,7 @@ class Factory
* @param EventDispatcher $eventDispatcher
* @return Downloader\DownloadManager
*/
public function createDownloadManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
public function createDownloadManager(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
{
$cache = null;
if ($config->get('cache-files-ttl') > 0) {
@ -412,18 +415,21 @@ class Factory
break;
}
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
$dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config));
$dm->setDownloader('hg', new Downloader\HgDownloader($io, $config));
$executor = new ProcessExecutor($io);
$fs = new Filesystem($executor);
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config, $executor, $fs));
$dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config, $executor, $fs));
$dm->setDownloader('hg', new Downloader\HgDownloader($io, $config, $executor, $fs));
$dm->setDownloader('perforce', new Downloader\PerforceDownloader($io, $config));
$dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('xz', new Downloader\XzDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('path', new Downloader\PathDownloader($io, $config, $eventDispatcher, $cache));
$dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs));
$dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs));
$dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache, $rfs));
$dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs));
$dm->setDownloader('xz', new Downloader\XzDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs));
$dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache, $rfs));
$dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $eventDispatcher, $cache, $rfs));
$dm->setDownloader('path', new Downloader\PathDownloader($io, $config, $eventDispatcher, $cache, $rfs));
return $dm;
}
@ -515,9 +521,13 @@ class Factory
*/
public static function createRemoteFilesystem(IOInterface $io, Config $config = null, $options = array())
{
static $warned = false;
$disableTls = false;
if (isset($config) && $config->get('disable-tls') === true) {
$io->write('<warning>You are running Composer with SSL/TLS protection disabled.</warning>');
if (!$warned) {
$io->write('<warning>You are running Composer with SSL/TLS protection disabled.</warning>');
}
$warned = true;
$disableTls = true;
} elseif (!extension_loaded('openssl')) {
throw new \RuntimeException('The openssl extension is required for SSL/TLS protection but is not available. '

View File

@ -59,7 +59,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
private $degradedMode = false;
private $rootData;
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
{
if (!preg_match('{^[\w.]+\??://}', $repoConfig['url'])) {
// assume http as the default protocol
@ -90,7 +90,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$this->io = $io;
$this->cache = new Cache($io, $config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->url), 'a-z0-9.$');
$this->loader = new ArrayLoader();
$this->rfs = Factory::createRemoteFilesystem($this->io, $this->config, $this->options);
$this->rfs = $rfs ?: Factory::createRemoteFilesystem($this->io, $this->config, $this->options);
$this->eventDispatcher = $eventDispatcher;
$this->repoConfig = $repoConfig;
}

View File

@ -16,6 +16,7 @@ use Composer\IO\IOInterface;
use Composer\Config;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Package\PackageInterface;
use Composer\Util\RemoteFilesystem;
/**
* Repositories manager.
@ -32,12 +33,14 @@ class RepositoryManager
private $io;
private $config;
private $eventDispatcher;
private $rfs;
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null)
public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, RemoteFilesystem $rfs = null)
{
$this->io = $io;
$this->config = $config;
$this->eventDispatcher = $eventDispatcher;
$this->rfs = $rfs;
}
/**
@ -102,7 +105,7 @@ class RepositoryManager
$class = $this->repositoryClasses[$type];
return new $class($config, $this->io, $this->config, $this->eventDispatcher);
return new $class($config, $this->io, $this->config, $this->eventDispatcher, $this->rfs);
}
/**

View File

@ -33,7 +33,7 @@ class FactoryMock extends Factory
return $config;
}
protected function addLocalRepository(RepositoryManager $rm, $vendorDir)
protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, $vendorDir)
{
}