Sfoglia il codice sorgente

Fix removal of packages installed in custom path with custom installers not overriding uninstall, fixes #2232

Jordi Boggiano 9 anni fa
parent
commit
d98b134dc3
1 ha cambiato i file con 20 aggiunte e 3 eliminazioni
  1. 20 3
      src/Composer/Installer/LibraryInstaller.php

+ 20 - 3
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)