From 51b1eeeb3f402fee6d302ab9cdcb782298e40923 Mon Sep 17 00:00:00 2001 From: Sebastian Kurfuerst Date: Tue, 23 Jul 2013 17:26:19 +0200 Subject: [PATCH] [BUGFIX] make sure composer/installers is always installed/updated first Resolves: #1147 --- src/Composer/Installer.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index ab937e47e..7b6a8d9a1 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -459,6 +459,8 @@ class Installer $this->io->write('Nothing to install or update'); } + $operations = $this->moveComposerInstallerToFrontIfNeeded($operations); + foreach ($operations as $operation) { // collect suggestions if ('install' === $operation->getJobType()) { @@ -534,6 +536,39 @@ class Installer return true; } + + /** + * Workaround: if your packages depend on composer/installers, we must be sure + * that composer/installers is installed / updated at FIRST; else it would lead + * to packages being installed multiple times in different folders, when running + * composer twice. + * + * While this does not fix the root-causes of https://github.com/composer/composer/issues/1147, + * it at least fixes the symptoms and makes usage of composer possible (again) + * in such scenarios. + * + * @param array $operations + * @return array the modified + */ + private function moveComposerInstallerToFrontIfNeeded($operations) + { + $operationForComposerInstallers = NULL; + $operations = array_filter($operations, function($operation) use (&$operationForComposerInstallers) { + if ( ($operation instanceof DependencyResolver\Operation\InstallOperation && $operation->getPackage()->getName() === 'composer/installers') + || ($operation instanceof DependencyResolver\Operation\UpdateOperation && $operation->getInitialPackage()->getName() === 'composer/installers') + ) { + $operationForComposerInstallers = $operation; + return FALSE; + } + + return TRUE; + }); + if ($operationForComposerInstallers !== NULL) { + array_unshift($operations, $operationForComposerInstallers); + } + return $operations; + } + private function createPool() { $minimumStability = $this->package->getMinimumStability();