From e697293cd93a8c47bded63c0f2a04f2c68306fae Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 4 May 2018 11:17:43 +0200 Subject: [PATCH] Handle broken symlinks more cleanly, fixes #7255 --- src/Composer/Installer/LibraryInstaller.php | 13 ++++++++++++- src/Composer/Util/Filesystem.php | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 4b1a95546..34fbbbee4 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/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); } /** diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 9e0e37279..2daa1ceb1 100644 --- a/src/Composer/Util/Filesystem.php +++ b/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; }