From 6c1f0cdf24dbc71839e87eab87e7c0c6fff97576 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 8 Jun 2021 21:53:20 +0200 Subject: [PATCH] Handle edge cases too in removeDirectoryPhp to avoid trying to delete symlinks and such, fixes #9955 --- src/Composer/Util/Filesystem.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 0be0300d0..2f5192096 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -166,7 +166,7 @@ class Filesystem * * @return bool|null Returns null, when no edge case was hit. Otherwise a bool whether removal was successfull */ - private function removeEdgeCases($directory) + private function removeEdgeCases($directory, $fallbackToPhp = true) { if ($this->isSymlinkedDirectory($directory)) { return $this->unlinkSymlinkedDirectory($directory); @@ -188,7 +188,7 @@ class Filesystem throw new \RuntimeException('Aborting an attempted deletion of '.$directory.', this was probably not intended, if it is a real use case please report it.'); } - if (!\function_exists('proc_open')) { + if (!\function_exists('proc_open') && $fallbackToPhp) { return $this->removeDirectoryPhp($directory); } @@ -207,6 +207,11 @@ class Filesystem */ public function removeDirectoryPhp($directory) { + $edgeCaseResult = $this->removeEdgeCases($directory, false); + if ($edgeCaseResult !== null) { + return $edgeCaseResult; + } + try { $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); } catch (\UnexpectedValueException $e) {