{@inheritdoc}

@param InstalledRepositoryInterface $repo    Repository,
@param PackageInterface             $initial Current package.
@param PackageInterface             $target  Newly installed package.

@return void
@since 0.1.0
517853
public function update(
        InstalledRepositoryInterface $repo,
        PackageInterface $initial,
        PackageInterface $target
    ) {
        $installPath = $this->getInstallPath($target);
        $junglist = new FileJunglist;
        $junglist->saveModifiedFiles($installPath);
        DebugPrinter::log('Updating package');
        parent::update($repo, $initial, $target);
        DebugPrinter::log('Post-update file rotate');
        $junglist->rotateInstalledFiles($installPath);
        $junglist->restoreModifiedFiles($installPath);
        DebugPrinter::log('Finished updating');
    }
265040
public function loadPackagistInfos(Repo $repo)
    {
        try {
            $this->composerReader->load($repo->getSlug());

            // Load package name
            if ($this->composerReader->has('name')) {
                $repo->setPackagistSlug($this->composerReader->get('name'));
            }

            // Load authors
            if ($this->composerReader->has('authors')) {
                $repo->setAuthors($this->composerReader->get('authors'));
            }

            // Load dependencies
            if ($this->composerReader->has('require')) {
                $repo->setDependencies($this->composerReader->get('require'));
            }
        } catch (\Exception $e) {
            // We do not want to throw exception here!
        }
    }
1250823
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
        /** @var GithubStrategy $strategy */
        $strategy = $updater->getStrategy();
        $strategy->setPackageName('TYPO3/Surf');
        $strategy->setPharName('surf.phar');

        $io = new SymfonyStyle($input, $output);

        $stability = $input->getOption('stability');
        if (empty($stability)) {
            $stability = GithubStrategy::STABLE;
        }
        /** @var GithubStrategy $strategy */
        $strategy = $updater->getStrategy();
        $strategy->setCurrentLocalVersion($this->getApplication()->getVersion());
        $strategy->setStability($stability);

        if ($input->getOption('check')) {
            $result = $updater->hasUpdate();
            if ($result) {
                $output->writeln(sprintf(
                    'The %s build available remotely is: %s',
                    $strategy->getStability() === GithubStrategy::ANY ? 'latest' : 'current ' . $strategy->getStability(),
                    $updater->getNewVersion()
                ));
            } elseif (false === $updater->getNewVersion()) {
                $output->writeln('There are no new builds available.');
            } else {
                $output->writeln(sprintf('You have the current %s build installed.', $strategy->getStability()));
            }
        } elseif ($input->getOption('rollback')) {
            $result = $updater->rollback();
            $result ? $output->writeln('Success!') : $output->writeln('Failure!');
        } else {
            $result = $updater->update();

            if ($result) {
                $io->success(
                    sprintf(
                        'Your %s has been updated from "%s" to "%s".',
                        $this->getLocalPharName(),
                        $updater->getOldVersion(),
                        $updater->getNewVersion()
                    )
                );
            } else {
                $io->success(sprintf('Your %s is already up to date.', $this->getLocalPharName()));
            }
        }
    }
185178
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $targetArg = rtrim($input->getArgument('target'), '/');

        if (!is_dir($targetArg)) {
            throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
        }

        $wantedVersion = $input->getOption('zeroclipboard-version');

        try {
            $versionConstraint = Constraint::parse($wantedVersion);
        } catch (UnexpectedValueException $e) {
            $output->writeln(
                '<error>Error:</error> <info>' .
                $wantedVersion . '</info> is not a valid version constraint.'
            );
            return;
        }

        $minimalConstraint =
            new SimpleConstraint(
                new Operator('>='),
                Version::parse($this->minimalSupportedVersion)
            );

        if(!$minimalConstraint->matches($versionConstraint)) {
            $output->writeln(
                '<error>Error:</error> <info>' .
                $wantedVersion . '</info> is not supported. Minimal version is: ' .
                $this->minimalSupportedVersion
            );
            return;
        }

        $curl = new Curl();
        $curl->get(
            'https://api.github.com' .
            '/repos/zeroclipboard/zeroclipboard/tags?per_page=100'
        );

        $versionToInstall = null;
        $versionToInstallObj = new Version(1, 0, 6);

        foreach(json_decode($curl->response) as $release) {
            try {
                $tag = Version::parse($release->name);
                if ($tag->getStability()->isStable()) {
                    $constraint = new SimpleConstraint(new Operator('='), $tag);
                    if ($constraint->isSubsetOf($versionConstraint)) {
                        if ($tag->compare($versionToInstallObj) > 0) {
                            $versionToInstall = $release->name;
                            $versionToInstallObj = $tag;
                        }
                    } else {
                    }
                }
            } catch(\Exception $e) {

            }
        }

        if(!$versionToInstall) {
            $output->writeln(
                '<error>Error:</error> <info>' .
                $wantedVersion . '</info> is greator than the last release. '
            );
            return;
        }

        /** @var Filesystem $filesystem */
        $filesystem = $this->getContainer()->get('filesystem');

        // Create the bundles directory otherwise symlink will fail.
        $bundlesDir = $targetArg . '/bundles/';
        $filesystem->mkdir($bundlesDir, 0777);

        $output->writeln(
            'Installing ZeroClipboard assets.'
        );

        $targetDir  = $bundlesDir . 'zeroclipboard-assets';

        $namespaceParts = explode('\\', __NAMESPACE__);
        array_pop($namespaceParts);

        $output->writeln(
            sprintf(
                'Installing assets for <comment>%s</comment> into <comment>%s</comment>',
                implode('\\', $namespaceParts),
                $targetDir
            )
        );

        $filesystem->remove($targetDir);

        $filesystem->mkdir($targetDir, 0777);

        $filesystem->mkdir($targetDir . '/tmp');

        $zip = file_get_contents(
            'https://github.com/zeroclipboard/zeroclipboard/archive/' . $versionToInstall . '.zip'
        );

        file_put_contents($targetDir . '/tmp/zeroclipboard.zip', $zip);

        $zip = new \ZipArchive;

        if ($zip->open($targetDir . '/tmp/zeroclipboard.zip') === TRUE) {
            $zip->extractTo($targetDir . '/tmp');
            $zip->close();

            if(file_exists($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist')) {
                $filesystem->mirror(
                    $targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist',
                    $targetDir
                );
            } else {
                $versionToInstall = $versionToInstallObj->getMajor() .'.' .
                    $versionToInstallObj->getMinor() .'.' .
                    $versionToInstallObj->getRevision();
                if(file_exists($targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist')) {
                    $filesystem->mirror(
                        $targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/dist',
                        $targetDir
                    );
                } else {
                    foreach( array(
                                 'ZeroClipboard.js',
                                 'ZeroClipboard.min.js',
                                 'ZeroClipboard.min.map',
                                 'ZeroClipboard.Core.js',
                                 'ZeroClipboard.Core.min.js',
                                 'ZeroClipboard.Core.min.map',
                                 'ZeroClipboard.swf',
                             ) as $file) {
                        if(
                        file_exists(
                            $targetDir .
                            '/tmp/zeroclipboard-' .
                            $versionToInstall .
                            '/' . $file)) {
                            $filesystem->copy(
                                $targetDir . '/tmp/zeroclipboard-' . $versionToInstall . '/' . $file,
                                $targetDir . '/' . $file
                            );
                        }
                    }
                }
            }
            $filesystem->remove($targetDir . '/tmp');
        } else {
            throw new FileException('File Error');
        }
    }
153894
public function setup($target)
    {
        $installer = tempnam(sys_get_temp_dir(), 'install');
        $handle = fopen($installer, 'w+');

        $request = $this->guzzle->get('https://getcomposer.org/installer', null, $handle);

        try {
            $response = $request->send();
            fclose($handle);
        } catch (GuzzleException $e) {
            fclose($handle);
            throw new RuntimeException('Unable to download composer install script.');
        }

        if (200 !== $response->getStatusCode()) {
            @unlink($installer);
            throw new RuntimeException('Unable to download composer install script.');
        }

        $dir = getcwd();
        if (!@chdir(dirname($target))) {
            throw new RuntimeException('Unable to move to target directory for composer install.');
        }

        $process = ProcessBuilder::create([$this->phpExecutable, $installer])
            ->setTimeout(300)
            ->getProcess()
        ;

        try {
            $process->run();
            @unlink($installer);
        } catch (ProcessException $e) {
            @unlink($installer);
            throw new RuntimeException('Unable run composer install script.');
        }

        if (!@rename(getcwd() . '/composer.phar', $target)) {
            throw new RuntimeException('Composer install failed.');
        }

        if (!@chdir($dir)) {
            throw new RuntimeException('Unable to move back to origin directory.');
        }

        if (!$process->isSuccessful()) {
            throw new RuntimeException('Composer install failed.');
        }

        if (!file_exists($target)) {
            throw new RuntimeException('Composer install failed.');
        }
    }
590247
private function copyTarget(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
    {
        if (self::DO_NOT_COPY === $this->copyTarget) {
            return;
        }

        if ((($oldValue = $target->getTarget()) === ($newValue = $source->getTarget()))
            || ($target->isTargetEmpty() && $source->isTargetEmpty())
        ) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Target is same, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );
            return;
        }

        if ((self::COPY_IF_EMPTY === $this->copyTarget) && !$target->isTargetEmpty()) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Target is not empty, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );

            return;
        }

        $this->logger->log(
            LogLevel::NOTICE,
            '{key}: Updating target value.',
            ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
        );

        if ($this->dryRun) {
            return;
        }

        if (null === $value = $source->getTarget()) {
            $target->clearTarget();
            return;
        }
        $target->setTarget($value);
    }
341104
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
    {
        if (!$repo->hasPackage($initial)) {
            throw new \InvalidArgumentException('Package is not installed: '.$initial);
        }

        $this->logVerbose(sprintf('Updating Contao sources for %s', $initial->getName()));

        $contaoRoot = $this->getContaoRoot();

        $this->removeSymlinks($initial, $contaoRoot, $this->getSources($initial));

        parent::update($repo, $initial, $target);

        $this->addSymlinks($target, $contaoRoot, $this->getSources($target));
        $this->addCopies($target, $this->getFilesRoot(), $this->getUserFiles($target), self::DUPLICATE_IGNORE);
        $this->addRunonces($target, $this->getRunonces($target));

        $this->logVerbose('');
    }
49618
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
    {
        new Textpattern();
        parent::update($repo, $initial, $target);
        $plugin = new $this->textpatternPackager($this->getInstallPath($target), $target);
        $plugin->update();
    }
1370129
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
    {
        new Textpattern();
        parent::install($repo, $package);
        $plugin = new $this->textpatternPackager($this->getInstallPath($package), $package);
        $plugin->install();
    }
72996
protected function runCommand(InputInterface $input, OutputInterface $output)
    {
        $repository = $this->getRepository($input, $output);
        $file = $input->getArgument('file');

        self::importFromFile(
            $file,
            $output,
            function (array $items, bool $lastIteration) use ($repository) {
                foreach ($items as $item) {
                    $repository->addItem($item);
                }

                $repository->flush(500, !$lastIteration);
            }
        );
    }
981287
protected function getPackage(RepositoryInterface $repos, $name)
    {
        $name = strtolower($name);
        $pool = new Pool('dev');
        $pool->addRepository($repos);
        $matches = $pool->whatProvides($name);

        foreach ($matches as $index => $package) {
            // skip providers/replacers
            if ($package->getName() !== $name) {
                unset($matches[$index]);
                continue;
            }

            return $package;
        }
    }
355314
protected function installNodePackage( $directory, OutputInterface $output, $package, $version = null, $dev = false ) {
		$package_manager = new Proxy();

		if ( $package_manager->installed( $directory, $package ) ) {
			throw new RuntimeException( 'Package is already installed.' );
		}

		$package_manager->install( $directory, $output, $package, $version, $dev );
	}
591179
protected function postInstallActions(PackageInterface $target, $downloadPath)
    {
        // @HACK to work around the security check in CI config files
        defined('BASEPATH') || define('BASEPATH', 1);

        switch ($target->getType()) {
            case 'codeigniter-core':
                // Move the core library extension out of the package directory and remove it
                $this->moveCoreFiles($downloadPath);
                break;

            case 'codeigniter-library':
                // Move the library files out of the package directory and remove it
                $wildcard = $this->package_subclass_prefix . "*.php";
                $path     = realpath($downloadPath) . '/' . $wildcard;
                if (count(glob($path)) > 0) {
                    $this->moveCoreFiles($downloadPath, $wildcard);
                }
                break;

            case 'projek-ci-module':
            case 'codeigniter-module':
                // If the module has migrations, copy them into the application migrations directory
                $moduleMigrations = $this->getModuleMigrations($downloadPath);
                if (count($moduleMigrations) > 0) {
                    $config = $this->getMigrationConfig($downloadPath);
                    $copied = $this->copyModuleMigrations($config, $moduleMigrations);

                    if ($copied) {
                        $this->io->write('    '.$copied.' migrations has been copied to app'.PHP_EOL);
                    } else {
                        $this->io->write('    no migrations available'.PHP_EOL);
                    }
                }
                break;

            // case 'projek-ci-module':
            //     If the module has migrations, copy them into the application migrations directory
            //     $moduleMigrations = $this->getModuleMigrations($downloadPath, 'asset/data');

            //     $confirm = true;
            //     if ($this->io->isInteractive()) {
            //         $question = 'Do you want to install migration files for ' . $target->getPrettyName();
            //         $confirm = $this->io->askConfirmation($question);
            //     }

            //     if (count($moduleMigrations) > 0 && $confirm) {
            //         $config = $this->getMigrationConfig($downloadPath);
            //         $this->copyModuleMigrations($config, $moduleMigrations);
            //         $this->io->write('<info>Installed</info>');
            //     }
            //     break;
        }
    }
626709
protected function execute(InputInterface $input, OutputInterface $output) : void
    {

        $io     = $this->getIO($input, $output);
        $config = $this->getConfig($input->getOption('configuration'), true);
        $repo   = new Repository(dirname($input->getOption('git-directory')));

        $installer = new Installer($io, $config, $repo);
        $installer->setForce($input->getOption('force'))
                  ->setHook((string) $input->getArgument('hook'));

        $installer->run();
    }
1321798
public function installPackage(PackageInterface $package, InstallerInterface $installer, $isDependency = false)
    {
        if (false !== strpos($package->getName(), 'github')) {
            // install from a github endpoint
            $name = basename($package->getName(), '.git');
            $repoUrl = $package->getName();
            $package = new Package($name, $package->getRequiredVersion());
            $this->repository->setUrl($repoUrl)->setHttpClient($this->githubClient);
            $package->setRepository($this->repository);
            $packageTag = $this->repository->findPackage($package->getRequiredVersion());
            if (is_null($packageTag)) {
                throw new RuntimeException(sprintf('Cannot find package %s version %s.', $package->getName(), $package->getRequiredVersion()));
            }
        } else {
            $packageTag = $this->getPackageTag($package, true);
            $package->setRepository($this->repository);
        }

        $package->setVersion($packageTag);

        $this->updateBowerFile($package, $isDependency);

        // if package is already installed, match current version with latest available version
        if ($this->isPackageInstalled($package)) {
            $this->output->writelnInfoPackage($package, 'validate', sprintf('%s against %s#%s', $packageTag, $package->getName(), $package->getRequiredVersion()));
            $packageBower = $this->config->getPackageBowerFileContent($package);
            if ($packageTag == $packageBower['version']) {
                // if version is fully matching, there's no need to install
                return;
            }
        }

        $this->cachePackage($package);

        $this->output->writelnInstalledPackage($package);
        $installer->install($package);

        $overrides = $this->config->getOverrideFor($package->getName());
        if (array_key_exists('dependencies', $overrides)) {
            $dependencies = $overrides['dependencies'];
        } else {
            $dependencies = $package->getRequires();
        }
        if (!empty($dependencies)) {
            foreach ($dependencies as $name => $version) {
                $depPackage = new Package($name, $version);
                if (!$this->isPackageInstalled($depPackage)) {
                    $this->installPackage($depPackage, $installer, true);
                } elseif ($this->isNeedUpdate($depPackage)) {
                    $this->updatePackage($depPackage, $installer);
                }
            }
        }
    }
187668
protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo)
    {
        $this->getIO()->write('<info>name</info>     : ' . $package->getPrettyName());
        $this->getIO()->write('<info>descrip.</info> : ' . $package->getDescription());
        $this->getIO()->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
        $this->printVersions($package, $versions, $installedRepo);
        $this->getIO()->write('<info>type</info>     : ' . $package->getType());
        $this->printLicenses($package);
        $this->getIO()->write('<info>source</info>   : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
        $this->getIO()->write('<info>dist</info>     : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
        $this->getIO()->write('<info>names</info>    : ' . implode(', ', $package->getNames()));

        if ($package->isAbandoned()) {
            $replacement = ($package->getReplacementPackage() !== null)
                ? ' The author suggests using the ' . $package->getReplacementPackage(). ' package instead.'
                : null;

            $this->getIO()->writeError(
                sprintf('<warning>Attention: This package is abandoned and no longer maintained.%s</warning>', $replacement)
            );
        }

        if ($package->getSupport()) {
            $this->getIO()->write("\n<info>support</info>");
            foreach ($package->getSupport() as $type => $value) {
                $this->getIO()->write('<comment>' . $type . '</comment> : '.$value);
            }
        }

        if ($package->getAutoload()) {
            $this->getIO()->write("\n<info>autoload</info>");
            foreach ($package->getAutoload() as $type => $autoloads) {
                $this->getIO()->write('<comment>' . $type . '</comment>');

                if ($type === 'psr-0') {
                    foreach ($autoloads as $name => $path) {
                        $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                    }
                } elseif ($type === 'psr-4') {
                    foreach ($autoloads as $name => $path) {
                        $this->getIO()->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                    }
                } elseif ($type === 'classmap') {
                    $this->getIO()->write(implode(', ', $autoloads));
                }
            }
            if ($package->getIncludePaths()) {
                $this->getIO()->write('<comment>include-path</comment>');
                $this->getIO()->write(implode(', ', $package->getIncludePaths()));
            }
        }
    }
1365577
public function updateCode( PackageInterface $initial, PackageInterface $target )
    {
        $actualLegacyDir = $this->ezpublishLegacyDir;
        $this->ezpublishLegacyDir = $this->generateTempDirName();
        if ( $this->io->isVerbose() )
        {
            $this->io->write( "Installing in temporary directory." );
        }

        $this->installCode( $target );

        $fileSystem = new Filesystem();
        if ( $this->io->isVerbose() )
        {
            $this->io->write( "Updating new code over existing installation." );
        }
        /// @todo the following function does not warn of any failures in copying stuff over. We should probably fix it...
        $fileSystem->copyThenRemove( $this->ezpublishLegacyDir, $actualLegacyDir );

        $this->ezpublishLegacyDir = $actualLegacyDir;
    }