From 1bf2df19dd5eaf129f331092e6b47ea1b6256aaa Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 2 Nov 2020 13:50:35 +0100 Subject: [PATCH] Avoid cleaning up $path in downloaders if it is the CWD (create-project use case), refs #9396 --- src/Composer/Downloader/ArchiveDownloader.php | 12 +++++++++--- src/Composer/Downloader/FileDownloader.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 66b075772..213f59c20 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -60,7 +60,11 @@ abstract class ArchiveDownloader extends FileDownloader } while (is_dir($temporaryDir)); $this->addCleanupPath($package, $temporaryDir); - $this->addCleanupPath($package, $path); + // avoid cleaning up $path if installing in "." for eg create-project as we can not + // delete the directory we are currently in on windows + if (!is_dir($path) || realpath($path) !== getcwd()) { + $this->addCleanupPath($package, realpath($path)); + } $this->filesystem->ensureDirectoryExists($temporaryDir); $fileName = $this->getFileName($package, $path); @@ -73,10 +77,12 @@ abstract class ArchiveDownloader extends FileDownloader $self->clearLastCacheWrite($package); // clean up - $filesystem->removeDirectory($path); $filesystem->removeDirectory($temporaryDir); + if (is_dir($path) && realpath($path) !== getcwd()) { + $filesystem->removeDirectory($path); + } $self->removeCleanupPath($package, $temporaryDir); - $self->removeCleanupPath($package, $path); + $self->removeCleanupPath($package, realpath($path)); }; $promise = null; diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index ece83a104..53fdb15a1 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -293,7 +293,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface } foreach ($dirsToCleanUp as $dir) { - if (is_dir($dir) && $this->filesystem->isDirEmpty($dir)) { + if (is_dir($dir) && $this->filesystem->isDirEmpty($dir) && realpath($dir) !== getcwd()) { $this->filesystem->removeDirectory($dir); } }