From 807600b255cafa7689071d09d75b1ddffb535c57 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 25 Sep 2013 21:07:55 +0200 Subject: [PATCH] Fix edge case where one adds a target-dir on a package that didnt have one before, refs #2279 --- src/Composer/Installer/LibraryInstaller.php | 10 +++++++++- tests/Composer/Test/Installer/LibraryInstallerTest.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index cb3808295..9d78ba1e6 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -161,7 +161,15 @@ class LibraryInstaller implements InstallerInterface $initialDownloadPath = $this->getInstallPath($initial); $targetDownloadPath = $this->getInstallPath($target); if ($targetDownloadPath !== $initialDownloadPath) { - $this->filesystem->copyThenRemove($initialDownloadPath, $targetDownloadPath); + // if the target is part of the initial dir, we force a remove + install + // to avoid the rename wiping the target dir as part of the initial dir cleanup + if (strpos($initialDownloadPath, $targetDownloadPath) === 0) { + $this->removeCode($initial); + $this->installCode($target); + return; + } + + $this->filesystem->rename($initialDownloadPath, $targetDownloadPath); } $this->downloadManager->update($initial, $target, $targetDownloadPath); } diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index 245969618..56e7e7415 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -135,7 +135,7 @@ class LibraryInstallerTest extends TestCase ->getMock(); $filesystem ->expects($this->once()) - ->method('copyThenRemove') + ->method('rename') ->with($this->vendorDir.'/package1', $this->vendorDir.'/package1/newtarget'); $initial = $this->createPackageMock();