Skip to content

Commit

Permalink
Handle edge cases too in removeDirectoryPhp to avoid trying to delete…
Browse files Browse the repository at this point in the history
… symlinks and such, fixes #9955
  • Loading branch information
Seldaek committed Jun 8, 2021
1 parent f61f2c6 commit 6c1f0cd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Composer/Util/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function removeDirectoryAsync($directory)
*
* @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);
Expand All @@ -188,7 +188,7 @@ private function removeEdgeCases($directory)
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);
}

Expand All @@ -207,6 +207,11 @@ private function removeEdgeCases($directory)
*/
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) {
Expand Down

0 comments on commit 6c1f0cd

Please sign in to comment.