1
0
Fork 0

Handle edge cases too in removeDirectoryPhp to avoid trying to delete symlinks and such, fixes #9955

pull/9959/head
Jordi Boggiano 2021-06-08 21:53:20 +02:00
parent f61f2c6872
commit 6c1f0cdf24
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 7 additions and 2 deletions

View File

@ -166,7 +166,7 @@ class Filesystem
* *
* @return bool|null Returns null, when no edge case was hit. Otherwise a bool whether removal was successfull * @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)) { if ($this->isSymlinkedDirectory($directory)) {
return $this->unlinkSymlinkedDirectory($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.'); 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); return $this->removeDirectoryPhp($directory);
} }
@ -207,6 +207,11 @@ class Filesystem
*/ */
public function removeDirectoryPhp($directory) public function removeDirectoryPhp($directory)
{ {
$edgeCaseResult = $this->removeEdgeCases($directory, false);
if ($edgeCaseResult !== null) {
return $edgeCaseResult;
}
try { try {
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS); $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
} catch (\UnexpectedValueException $e) { } catch (\UnexpectedValueException $e) {