/**
  * Constructor.
  *
  * @param IOInterface      $io               The IO instance
  * @param Config           $config           The composer configuration
  * @param ProcessExecutor  $process          Process instance, injectable for mocking
  * @param RemoteFilesystem $remoteFilesystem Remote Filesystem, injectable for mocking
  */
 public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
 {
     $this->io = $io;
     $this->config = $config;
     $this->process = $process ?: new ProcessExecutor();
     $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config);
 }
 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
         $repoConfig['url'] = 'http://' . $repoConfig['url'];
     }
     $repoConfig['url'] = rtrim($repoConfig['url'], '/');
     if ('https?' === substr($repoConfig['url'], 0, 6)) {
         $repoConfig['url'] = (extension_loaded('openssl') ? 'https' : 'http') . substr($repoConfig['url'], 6);
     }
     $urlBits = parse_url($repoConfig['url']);
     if ($urlBits === false || empty($urlBits['scheme'])) {
         throw new \UnexpectedValueException('Invalid url given for Composer repository: ' . $repoConfig['url']);
     }
     if (!isset($repoConfig['options'])) {
         $repoConfig['options'] = array();
     }
     if (isset($repoConfig['allow_ssl_downgrade']) && true === $repoConfig['allow_ssl_downgrade']) {
         $this->allowSslDowngrade = true;
     }
     $this->config = $config;
     $this->options = $repoConfig['options'];
     $this->url = $repoConfig['url'];
     $this->baseUrl = rtrim(preg_replace('{^(.*)(?:/[^/\\]+.json)?(?:[?#].*)?$}', '$1', $this->url), '/');
     $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 = $rfs ?: Factory::createRemoteFilesystem($this->io, $this->config, $this->options);
     $this->eventDispatcher = $eventDispatcher;
     $this->repoConfig = $repoConfig;
 }
Exemple #3
0
 /**
  * Constructor.
  *
  * @param IOInterface      $io              The IO instance
  * @param Config           $config          The config
  * @param EventDispatcher  $eventDispatcher The event dispatcher
  * @param Cache            $cache           Optional cache instance
  * @param RemoteFilesystem $rfs             The remote filesystem
  * @param Filesystem       $filesystem      The filesystem
  */
 public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, RemoteFilesystem $rfs = null, Filesystem $filesystem = null)
 {
     $this->io = $io;
     $this->config = $config;
     $this->eventDispatcher = $eventDispatcher;
     $this->rfs = $rfs ?: Factory::createRemoteFilesystem($this->io, $config);
     $this->filesystem = $filesystem ?: new Filesystem();
     $this->cache = $cache;
     if ($this->cache && $this->cache->gcIsNecessary()) {
         $this->cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
     }
 }
 /**
  * @return RepositoryInterface[]
  */
 public static function defaultRepos(IOInterface $io = null, Config $config = null, RepositoryManager $rm = null)
 {
     if (!$config) {
         $config = Factory::createConfig($io);
     }
     if (!$rm) {
         if (!$io) {
             throw new \InvalidArgumentException('This function requires either an IOInterface or a RepositoryManager');
         }
         $rm = static::manager($io, $config, null, Factory::createRemoteFilesystem($io, $config));
     }
     return static::createRepos($rm, $config->getRepositories());
 }
Exemple #5
0
 /**
  * Constructor.
  *
  * @param array            $repoConfig       The repository configuration
  * @param IOInterface      $io               The IO instance
  * @param Config           $config           The composer configuration
  * @param ProcessExecutor  $process          Process instance, injectable for mocking
  * @param RemoteFilesystem $remoteFilesystem Remote Filesystem, injectable for mocking
  */
 public final function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
 {
     if (Filesystem::isLocalPath($repoConfig['url'])) {
         $repoConfig['url'] = Filesystem::getPlatformPath($repoConfig['url']);
     }
     $this->url = $repoConfig['url'];
     $this->originUrl = $repoConfig['url'];
     $this->repoConfig = $repoConfig;
     $this->io = $io;
     $this->config = $config;
     $this->process = $process ?: new ProcessExecutor($io);
     $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config);
 }
Exemple #6
0
 public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, RemoteFilesystem $rfs = null)
 {
     if (!preg_match('{^https?://}', $repoConfig['url'])) {
         $repoConfig['url'] = 'http://' . $repoConfig['url'];
     }
     $urlBits = parse_url($repoConfig['url']);
     if (empty($urlBits['scheme']) || empty($urlBits['host'])) {
         throw new \UnexpectedValueException('Invalid url given for PEAR repository: ' . $repoConfig['url']);
     }
     $this->url = rtrim($repoConfig['url'], '/');
     $this->io = $io;
     $this->rfs = $rfs ?: Factory::createRemoteFilesystem($this->io, $config);
     $this->vendorAlias = isset($repoConfig['vendor-alias']) ? $repoConfig['vendor-alias'] : null;
     $this->versionParser = new VersionParser();
     $this->repoConfig = $repoConfig;
 }
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $config = Factory::createConfig();
        if ($config->get('disable-tls') === true) {
            $baseUrl = 'http://' . self::HOMEPAGE;
        } else {
            $baseUrl = 'https://' . self::HOMEPAGE;
        }
        $io = $this->getIO();
        $remoteFilesystem = Factory::createRemoteFilesystem($io, $config);
        $versionsUtil = new Versions($config, $remoteFilesystem);
        // switch channel if requested
        foreach (array('stable', 'preview', 'snapshot') as $channel) {
            if ($input->getOption($channel)) {
                $versionsUtil->setChannel($channel);
            }
        }
        $cacheDir = $config->get('cache-dir');
        $rollbackDir = $config->get('data-dir');
        $home = $config->get('home');
        $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
        if ($input->getOption('update-keys')) {
            return $this->fetchKeys($io, $config);
        }
        // check if current dir is writable and if not try the cache dir from settings
        $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
        // check for permissions in local filesystem before start connection process
        if (!is_writable($tmpDir)) {
            throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written');
        }
        if ($input->getOption('rollback')) {
            return $this->rollback($output, $rollbackDir, $localFilename);
        }
        $latest = $versionsUtil->getLatest();
        $latestVersion = $latest['version'];
        $updateVersion = $input->getArgument('version') ?: $latestVersion;
        if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
            $io->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
            return 1;
        }
        if (Composer::VERSION === $updateVersion) {
            $io->writeError('<info>You are already using composer version ' . $updateVersion . '.</info>');
            // remove all backups except for the most recent, if any
            if ($input->getOption('clean-backups')) {
                $this->cleanBackups($rollbackDir, $this->getLastBackupVersion($rollbackDir));
            }
            return 0;
        }
        $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
        $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
        $updatingToTag = !preg_match('{^[0-9a-f]{40}$}', $updateVersion);
        $io->write(sprintf("Updating to version <info>%s</info>.", $updateVersion));
        $remoteFilename = $baseUrl . ($updatingToTag ? "/download/{$updateVersion}/composer.phar" : '/composer.phar');
        $signature = $remoteFilesystem->getContents(self::HOMEPAGE, $remoteFilename . '.sig', false);
        $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
        if (!file_exists($tempFilename) || !$signature) {
            $io->writeError('<error>The download of the new composer version failed for an unexpected reason</error>');
            return 1;
        }
        // verify phar signature
        if (!extension_loaded('openssl') && $config->get('disable-tls')) {
            $io->writeError('<warning>Skipping phar signature verification as you have disabled OpenSSL via config.disable-tls</warning>');
        } else {
            if (!extension_loaded('openssl')) {
                throw new \RuntimeException('The openssl extension is required for phar signatures to be verified but it is not available. ' . 'If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the \'disable-tls\' option to true.');
            }
            $sigFile = 'file://' . $home . '/' . ($updatingToTag ? 'keys.tags.pub' : 'keys.dev.pub');
            if (!file_exists($sigFile)) {
                file_put_contents($home . '/keys.dev.pub', <<<DEVPUBKEY
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnBDHjZS6e0ZMoK3xTD7f
FNCzlXjX/Aie2dit8QXA03pSrOTbaMnxON3hUL47Lz3g1SC6YJEMVHr0zYq4elWi
i3ecFEgzLcj+pZM5X6qWu2Ozz4vWx3JYo1/a/HYdOuW9e3lwS8VtS0AVJA+U8X0A
hZnBmGpltHhO8hPKHgkJtkTUxCheTcbqn4wGHl8Z2SediDcPTLwqezWKUfrYzu1f
o/j3WFwFs6GtK4wdYtiXr+yspBZHO3y1udf8eFFGcb2V3EaLOrtfur6XQVizjOuk
8lw5zzse1Qp/klHqbDRsjSzJ6iL6F4aynBc6Euqt/8ccNAIz0rLjLhOraeyj4eNn
8iokwMKiXpcrQLTKH+RH1JCuOVxQ436bJwbSsp1VwiqftPQieN+tzqy+EiHJJmGf
TBAbWcncicCk9q2md+AmhNbvHO4PWbbz9TzC7HJb460jyWeuMEvw3gNIpEo2jYa9
pMV6cVqnSa+wOc0D7pC9a6bne0bvLcm3S+w6I5iDB3lZsb3A9UtRiSP7aGSo7D72
8tC8+cIgZcI7k9vjvOqH+d7sdOU2yPCnRY6wFh62/g8bDnUpr56nZN1G89GwM4d4
r/TU7BQQIzsZgAiqOGXvVklIgAMiV0iucgf3rNBLjjeNEwNSTTG9F0CtQ+7JLwaE
wSEuAuRm+pRqi8BRnQ/GKUcCAwEAAQ==
-----END PUBLIC KEY-----
DEVPUBKEY
);
                file_put_contents($home . '/keys.tags.pub', <<<TAGSPUBKEY
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0Vi/2K6apCVj76nCnCl2
MQUPdK+A9eqkYBacXo2wQBYmyVlXm2/n/ZsX6pCLYPQTHyr5jXbkQzBw8SKqPdlh
vA7NpbMeNCz7wP/AobvUXM8xQuXKbMDTY2uZ4O7sM+PfGbptKPBGLe8Z8d2sUnTO
bXtX6Lrj13wkRto7st/w/Yp33RHe9SlqkiiS4MsH1jBkcIkEHsRaveZzedUaxY0M
mba0uPhGUInpPzEHwrYqBBEtWvP97t2vtfx8I5qv28kh0Y6t+jnjL1Urid2iuQZf
noCMFIOu4vksK5HxJxxrN0GOmGmwVQjOOtxkwikNiotZGPR4KsVj8NnBrLX7oGuM
nQvGciiu+KoC2r3HDBrpDeBVdOWxDzT5R4iI0KoLzFh2pKqwbY+obNPS2bj+2dgJ
rV3V5Jjry42QOCBN3c88wU1PKftOLj2ECpewY6vnE478IipiEu7EAdK8Zwj2LmTr
RKQUSa9k7ggBkYZWAeO/2Ag0ey3g2bg7eqk+sHEq5ynIXd5lhv6tC5PBdHlWipDK
tl2IxiEnejnOmAzGVivE1YGduYBjN+mjxDVy8KGBrjnz1JPgAvgdwJ2dYw4Rsc/e
TzCFWGk/HM6a4f0IzBWbJ5ot0PIi4amk07IotBXDWwqDiQTwyuGCym5EqWQ2BD95
RGv89BPD+2DLnJysngsvVaUCAwEAAQ==
-----END PUBLIC KEY-----
TAGSPUBKEY
);
            }
            $pubkeyid = openssl_pkey_get_public($sigFile);
            $algo = defined('OPENSSL_ALGO_SHA384') ? OPENSSL_ALGO_SHA384 : 'SHA384';
            if (!in_array('SHA384', openssl_get_md_methods())) {
                throw new \RuntimeException('SHA384 is not supported by your openssl extension, could not verify the phar file integrity');
            }
            $signature = json_decode($signature, true);
            $signature = base64_decode($signature['sha384']);
            $verified = 1 === openssl_verify(file_get_contents($tempFilename), $signature, $pubkeyid, $algo);
            openssl_free_key($pubkeyid);
            if (!$verified) {
                throw new \RuntimeException('The phar signature did not match the file you downloaded, this means your public keys are outdated or that the phar file is corrupt/has been modified');
            }
        }
        // remove saved installations of composer
        if ($input->getOption('clean-backups')) {
            $this->cleanBackups($rollbackDir);
        }
        if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
            @unlink($tempFilename);
            $io->writeError('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
            $io->writeError('<error>Please re-run the self-update command to try again.</error>');
            return 1;
        }
        if (file_exists($backupFile)) {
            $io->writeError('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
        } else {
            $io->writeError('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
        }
    }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $composer = $this->getComposer(false);
     $io = $this->getIO();
     if ($composer) {
         $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
         $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
         $io->write('Checking composer.json: ', false);
         $this->outputResult($this->checkComposerSchema());
     }
     if ($composer) {
         $config = $composer->getConfig();
     } else {
         $config = Factory::createConfig();
     }
     $this->rfs = Factory::createRemoteFilesystem($io, $config);
     $this->process = new ProcessExecutor($io);
     $io->write('Checking platform settings: ', false);
     $this->outputResult($this->checkPlatform());
     $io->write('Checking git settings: ', false);
     $this->outputResult($this->checkGit());
     $io->write('Checking http connectivity to packagist: ', false);
     $this->outputResult($this->checkHttp('http', $config));
     $io->write('Checking https connectivity to packagist: ', false);
     $this->outputResult($this->checkHttp('https', $config));
     $opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
     if (!empty($opts['http']['proxy'])) {
         $io->write('Checking HTTP proxy: ', false);
         $this->outputResult($this->checkHttpProxy());
         $io->write('Checking HTTP proxy support for request_fulluri: ', false);
         $this->outputResult($this->checkHttpProxyFullUriRequestParam());
         $io->write('Checking HTTPS proxy support for request_fulluri: ', false);
         $this->outputResult($this->checkHttpsProxyFullUriRequestParam());
     }
     if ($oauth = $config->get('github-oauth')) {
         foreach ($oauth as $domain => $token) {
             $io->write('Checking ' . $domain . ' oauth access: ', false);
             $this->outputResult($this->checkGithubOauth($domain, $token));
         }
     } else {
         $io->write('Checking github.com rate limit: ', false);
         try {
             $rate = $this->getGithubRateLimit('github.com');
             $this->outputResult(true);
             if (10 > $rate['remaining']) {
                 $io->write('<warning>WARNING</warning>');
                 $io->write(sprintf('<comment>Github has a rate limit on their API. ' . 'You currently have <options=bold>%u</options=bold> ' . 'out of <options=bold>%u</options=bold> requests left.' . PHP_EOL . 'See https://developer.github.com/v3/#rate-limiting and also' . PHP_EOL . '    https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>', $rate['remaining'], $rate['limit']));
             }
         } catch (\Exception $e) {
             if ($e instanceof TransportException && $e->getCode() === 401) {
                 $this->outputResult('<comment>The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it</comment>');
             } else {
                 $this->outputResult($e);
             }
         }
     }
     $io->write('Checking disk free space: ', false);
     $this->outputResult($this->checkDiskSpace($config));
     $io->write('Checking pubkeys: ', false);
     $this->outputResult($this->checkPubKeys($config));
     $io->write('Checking composer version: ', false);
     $this->outputResult($this->checkVersion());
     return $this->failures;
 }
 protected function installRootPackage(IOInterface $io, Config $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disablePlugins = false, $noScripts = false, $keepVcs = false, $noProgress = false)
 {
     if (null === $repositoryUrl) {
         $sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
     } elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION) && file_exists($repositoryUrl)) {
         $json = new JsonFile($repositoryUrl, Factory::createRemoteFilesystem($io, $config));
         $data = $json->read();
         if (!empty($data['packages']) || !empty($data['includes']) || !empty($data['provider-includes'])) {
             $sourceRepo = new ComposerRepository(array('url' => 'file://' . strtr(realpath($repositoryUrl), '\\', '/')), $io, $config);
         } else {
             $sourceRepo = new FilesystemRepository($json);
         }
     } elseif (0 === strpos($repositoryUrl, 'http')) {
         $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
     } else {
         throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
     }
     $parser = new VersionParser();
     $requirements = $parser->parseNameVersionPairs(array($packageName));
     $name = strtolower($requirements[0]['name']);
     if (!$packageVersion && isset($requirements[0]['version'])) {
         $packageVersion = $requirements[0]['version'];
     }
     if (null === $stability) {
         if (preg_match('{^[^,\\s]*?@(' . implode('|', array_keys(BasePackage::$stabilities)) . ')$}i', $packageVersion, $match)) {
             $stability = $match[1];
         } else {
             $stability = VersionParser::parseStability($packageVersion);
         }
     }
     $stability = VersionParser::normalizeStability($stability);
     if (!isset(BasePackage::$stabilities[$stability])) {
         throw new \InvalidArgumentException('Invalid stability provided (' . $stability . '), must be one of: ' . implode(', ', array_keys(BasePackage::$stabilities)));
     }
     $pool = new Pool($stability);
     $pool->addRepository($sourceRepo);
     // using those 3 constants to build a version without the 'extra' bit that can contain garbage
     $phpVersion = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
     // find the latest version if there are multiple
     $versionSelector = new VersionSelector($pool);
     $package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability);
     if (!$package) {
         throw new \InvalidArgumentException("Could not find package {$name}" . ($packageVersion ? " with version {$packageVersion}." : " with stability {$stability}."));
     }
     if (null === $directory) {
         $parts = explode("/", $name, 2);
         $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
     }
     // handler Ctrl+C for unix-like systems
     if (function_exists('pcntl_signal')) {
         declare (ticks=100);
         pcntl_signal(SIGINT, function () use($directory) {
             $fs = new Filesystem();
             $fs->removeDirectory($directory);
             exit(130);
         });
     }
     $io->writeError('<info>Installing ' . $package->getName() . ' (' . $package->getFullPrettyVersion(false) . ')</info>');
     if ($disablePlugins) {
         $io->writeError('<info>Plugins have been disabled.</info>');
     }
     if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
         $package->setSourceReference(substr($package->getPrettyVersion(), 4));
     }
     $dm = $this->createDownloadManager($io, $config);
     $dm->setPreferSource($preferSource)->setPreferDist($preferDist)->setOutputProgress(!$noProgress);
     $projectInstaller = new ProjectInstaller($directory, $dm);
     $im = $this->createInstallationManager();
     $im->addInstaller($projectInstaller);
     $im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package));
     $im->notifyInstalls($io);
     $installedFromVcs = 'source' === $package->getInstallationSource();
     $io->writeError('<info>Created project in ' . $directory . '</info>');
     chdir($directory);
     $_SERVER['COMPOSER_ROOT_VERSION'] = $package->getPrettyVersion();
     putenv('COMPOSER_ROOT_VERSION=' . $_SERVER['COMPOSER_ROOT_VERSION']);
     return $installedFromVcs;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = Factory::createConfig();
     if ($config->get('disable-tls') === true) {
         $baseUrl = 'http://' . self::HOMEPAGE;
     } else {
         $baseUrl = 'https://' . self::HOMEPAGE;
     }
     $io = $this->getIO();
     $remoteFilesystem = Factory::createRemoteFilesystem($io, $config);
     $cacheDir = $config->get('cache-dir');
     $rollbackDir = $config->get('data-dir');
     $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
     // check if current dir is writable and if not try the cache dir from settings
     $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
     // check for permissions in local filesystem before start connection process
     if (!is_writable($tmpDir)) {
         throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written');
     }
     if (!is_writable($localFilename)) {
         throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written');
     }
     if ($input->getOption('rollback')) {
         return $this->rollback($output, $rollbackDir, $localFilename);
     }
     $latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false));
     $updateVersion = $input->getArgument('version') ?: $latestVersion;
     if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
         $io->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
         return 1;
     }
     if (Composer::VERSION === $updateVersion) {
         $io->writeError('<info>You are already using composer version ' . $updateVersion . '.</info>');
         return 0;
     }
     $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
     $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
     $io->writeError(sprintf("Updating to version <info>%s</info>.", $updateVersion));
     $remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
     $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
     if (!file_exists($tempFilename)) {
         $io->writeError('<error>The download of the new composer version failed for an unexpected reason</error>');
         return 1;
     }
     // remove saved installations of composer
     if ($input->getOption('clean-backups')) {
         $finder = $this->getOldInstallationFinder($rollbackDir);
         $fs = new Filesystem();
         foreach ($finder as $file) {
             $file = (string) $file;
             $io->writeError('<info>Removing: ' . $file . '</info>');
             $fs->remove($file);
         }
     }
     if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
         $io->writeError('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
         $io->writeError('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
     if (file_exists($backupFile)) {
         $io->writeError('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
     } else {
         $io->writeError('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
     }
 }