From 756f9e10b7a35a34585a4cfff3ff40679cf98651 Mon Sep 17 00:00:00 2001 From: Niels Keurentjes Date: Thu, 25 Feb 2016 22:29:55 +0100 Subject: [PATCH] Further protect junctioned path repos from accidentally deleting source packages. --- src/Composer/Downloader/PathDownloader.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Composer/Downloader/PathDownloader.php b/src/Composer/Downloader/PathDownloader.php index 1156ff62d..afb3e5de3 100644 --- a/src/Composer/Downloader/PathDownloader.php +++ b/src/Composer/Downloader/PathDownloader.php @@ -101,4 +101,25 @@ class PathDownloader extends FileDownloader $this->io->writeError(''); } + + /** + * {@inheritDoc} + */ + public function remove(PackageInterface $package, $path) + { + /** + * For junctions don't blindly rely on Filesystem::removeDirectory as it may be overzealous. If a process + * inadvertently locks the file the removal will fail, but it would fall back to recursive delete which + * is disastrous within a junction. So in that case we have no other real choice but to fail hard. + */ + if (Platform::isWindows() && $this->filesystem->isJunction($path)) { + $this->io->writeError(" - Removing junction for " . $package->getName() . " (" . $package->getFullPrettyVersion() . ")"); + if (!$this->filesystem->removeJunction($path)) { + $this->io->writeError("Could not remove junction at " . $path . " - is another process locking it?"); + throw new \RuntimeException('Could not reliably remove junction for package ' . $package->getName()); + } + } else { + parent::remove($package, $path); + } + } }