From 7649c8438da5db345fac9fa68b5029fc874f2325 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 11 Aug 2020 09:42:16 +0200 Subject: [PATCH] Fix exception when using create-project in current directory, fixes #9073 --- src/Composer/Downloader/ArchiveDownloader.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index 7cf19deee..ba19aa58b 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -46,10 +46,17 @@ abstract class ArchiveDownloader extends FileDownloader $this->io->writeError('Extracting archive', false); } - $this->filesystem->emptyDirectory($path); + $vendorDir = $this->config->get('vendor-dir'); + + // clean up the target directory, unless it contains the vendor dir, as the vendor dir contains + // the archive to be extracted. This is the case when installing with create-project in the current directory + // but in that case we ensure the directory is empty already in ProjectInstaller so no need to empty it here. + if (false === strpos($this->filesystem->normalizePath($vendorDir), $this->filesystem->normalizePath($path).DIRECTORY_SEPARATOR)) { + $this->filesystem->emptyDirectory($path); + } do { - $temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8); + $temporaryDir = $vendorDir.'/composer/'.substr(md5(uniqid('', true)), 0, 8); } while (is_dir($temporaryDir)); $this->addCleanupPath($package, $temporaryDir);