From 7d3f45cf04273d10f8c2eeefac84975d555e1917 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 13 Apr 2020 12:15:17 +0200 Subject: [PATCH] Avoid errors in cleanup, fixes #8766, fixes #8764 --- src/Composer/Downloader/FileDownloader.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 9e0e2d2bf..d13d9f105 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -239,14 +239,17 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface if (file_exists($fileName)) { $this->filesystem->unlink($fileName); } - if (is_dir($path) && $this->filesystem->isDirEmpty($this->config->get('vendor-dir').'/composer/')) { - $this->filesystem->removeDirectory($this->config->get('vendor-dir').'/composer/'); - } - if (is_dir($path) && $this->filesystem->isDirEmpty($this->config->get('vendor-dir'))) { - $this->filesystem->removeDirectory($this->config->get('vendor-dir')); - } - if (is_dir($path) && $this->filesystem->isDirEmpty($path)) { - $this->filesystem->removeDirectory($path); + + $dirsToCleanUp = array( + $this->config->get('vendor-dir').'/composer/', + $this->config->get('vendor-dir'), + $path, + ); + + foreach ($dirsToCleanUp as $dir) { + if (is_dir($dir) && $this->filesystem->isDirEmpty($dir)) { + $this->filesystem->removeDirectory($dir); + } } }