From d98b134dc3ef7d5bd4b6e37c9621a811f8f1599d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 19 Nov 2015 16:35:33 +0000 Subject: [PATCH] Fix removal of packages installed in custom path with custom installers not overriding uninstall, fixes #2232 --- src/Composer/Installer/LibraryInstaller.php | 33 ++++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 9c272c9dc..9b9e3990b 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -140,17 +140,34 @@ class LibraryInstaller implements InstallerInterface * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) - { - $targetDir = $package->getTargetDir(); - - return $this->getPackageBasePath($package) . ($targetDir ? '/'.$targetDir : ''); - } - - protected function getPackageBasePath(PackageInterface $package) { $this->initializeVendorDir(); - return ($this->vendorDir ? $this->vendorDir.'/' : '') . $package->getPrettyName(); + $basePath = ($this->vendorDir ? $this->vendorDir.'/' : '') . $package->getPrettyName(); + $targetDir = $package->getTargetDir(); + + return $basePath . ($targetDir ? '/'.$targetDir : ''); + } + + /** + * Returns the base path of the package without target-dir path + * + * It is used for BC as getInstallPath tends to be overriden by + * installer plugins but not getPackageBasePath + * + * @param PackageInterface $package + * @return string + */ + protected function getPackageBasePath(PackageInterface $package) + { + $installPath = $this->getInstallPath($package); + $targetDir = $package->getTargetDir(); + + if ($targetDir) { + return preg_replace('{/*'.str_replace('/', '/+', preg_quote($targetDir)).'/?$}', '', $installPath); + } + + return $installPath; } protected function installCode(PackageInterface $package)