From 73251691a0be65440c722461cb38f8574cea0c25 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 28 Mar 2020 20:36:37 +0100 Subject: [PATCH] Avoid emptying the directory before extracting an archive into it, check that it is empty instead --- src/Composer/Downloader/ArchiveDownloader.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index be863f1d3..0233d5b14 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -38,7 +38,10 @@ abstract class ArchiveDownloader extends FileDownloader $this->io->writeError('Extracting archive', false); } - $this->filesystem->emptyDirectory($path); + $this->filesystem->ensureDirectoryExists($path); + if (!$this->filesystem->isDirEmpty($path)) { + throw new \RuntimeException('Expected empty path to extract '.$package.' into but directory exists: '.$path); + } $temporaryDir = $this->config->get('vendor-dir').'/composer/'.substr(md5(uniqid('', true)), 0, 8); $fileName = $this->getFileName($package, $path);