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 | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 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 @@ -141,16 +141,33 @@ class LibraryInstaller implements InstallerInterface */ public function getInstallPath(PackageInterface $package) { + $this->initializeVendorDir(); + + $basePath = ($this->vendorDir ? $this->vendorDir.'/' : '') . $package->getPrettyName(); $targetDir = $package->getTargetDir(); - return $this->getPackageBasePath($package) . ($targetDir ? '/'.$targetDir : ''); + 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) { - $this->initializeVendorDir(); + $installPath = $this->getInstallPath($package); + $targetDir = $package->getTargetDir(); + + if ($targetDir) { + return preg_replace('{/*'.str_replace('/', '/+', preg_quote($targetDir)).'/?$}', '', $installPath); + } - return ($this->vendorDir ? $this->vendorDir.'/' : '') . $package->getPrettyName(); + return $installPath; } protected function installCode(PackageInterface $package)