Browse Source

Handle broken symlinks more cleanly, fixes #7255

Jordi Boggiano 6 years ago
parent
commit
e697293cd9
2 changed files with 16 additions and 1 deletions
  1. 12 1
      src/Composer/Installer/LibraryInstaller.php
  2. 4 0
      src/Composer/Util/Filesystem.php

+ 12 - 1
src/Composer/Installer/LibraryInstaller.php

@@ -18,6 +18,7 @@ use Composer\Repository\InstalledRepositoryInterface;
 use Composer\Package\PackageInterface;
 use Composer\Util\Filesystem;
 use Composer\Util\Silencer;
+use Composer\Util\Platform;
 
 /**
  * Package installation manager.
@@ -71,7 +72,17 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
      */
     public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
     {
-        return $repo->hasPackage($package) && is_readable($this->getInstallPath($package));
+        if (!$repo->hasPackage($package)) {
+            return false;
+        }
+
+        $installPath = $this->getInstallPath($package);
+
+        if (is_readable($installPath)) {
+            return true;
+        }
+
+        return (Platform::isWindows() && $this->filesystem->isJunction($installPath)) || is_link($installPath);
     }
 
     /**

+ 4 - 0
src/Composer/Util/Filesystem.php

@@ -103,6 +103,10 @@ class Filesystem
             return $this->removeJunction($directory);
         }
 
+        if (is_link($directory)) {
+            return unlink($directory);
+        }
+
         if (!file_exists($directory) || !is_dir($directory)) {
             return true;
         }