diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index aab3f4737..b1677cec2 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -160,9 +160,11 @@ class LibraryInstaller implements InstallerInterface $initialDownloadPath = $this->getInstallPath($initial); $targetDownloadPath = $this->getInstallPath($target); if ($targetDownloadPath !== $initialDownloadPath) { - // if the target is part of the initial dir, we force a remove + install + // if the target and initial dirs intersect, 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) { + if (substr($initialDownloadPath, 0, strlen($targetDownloadPath)) === $targetDownloadPath + || substr($targetDownloadPath, 0, strlen($initialDownloadPath)) === $initialDownloadPath + ) { $this->removeCode($initial); $this->installCode($target); diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index 56e7e7415..6230752e5 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -136,7 +136,7 @@ class LibraryInstallerTest extends TestCase $filesystem ->expects($this->once()) ->method('rename') - ->with($this->vendorDir.'/package1', $this->vendorDir.'/package1/newtarget'); + ->with($this->vendorDir.'/package1/oldtarget', $this->vendorDir.'/package1/newtarget'); $initial = $this->createPackageMock(); $target = $this->createPackageMock(); @@ -146,6 +146,11 @@ class LibraryInstallerTest extends TestCase ->method('getPrettyName') ->will($this->returnValue('package1')); + $initial + ->expects($this->once()) + ->method('getTargetDir') + ->will($this->returnValue('oldtarget')); + $target ->expects($this->once()) ->method('getPrettyName')