From 9364eca21a445050cb45254d7e231999c3ef58d5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 25 Aug 2021 17:44:20 +0200 Subject: [PATCH] [Finder] always return RecursiveDirectoryIterator from its getChildren() method --- .../Iterator/RecursiveDirectoryIterator.php | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php b/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php index 9ff0787661937..7e389273f9f42 100644 --- a/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php +++ b/src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php @@ -79,7 +79,31 @@ public function current() } /** - * @return \RecursiveIterator + * @param bool $allowLinks + * + * @return bool + */ + #[\ReturnTypeWillChange] + public function hasChildren($allowLinks = false) + { + $hasChildren = parent::hasChildren($allowLinks); + + if (!$hasChildren || !$this->ignoreUnreadableDirs) { + return $hasChildren; + } + + try { + parent::getChildren(); + + return true; + } catch (\UnexpectedValueException $e) { + // If directory is unreadable and finder is set to ignore it, skip children + return false; + } + } + + /** + * @return \RecursiveDirectoryIterator * * @throws AccessDeniedException */ @@ -100,12 +124,7 @@ public function getChildren() return $children; } catch (\UnexpectedValueException $e) { - if ($this->ignoreUnreadableDirs) { - // If directory is unreadable and finder is set to ignore it, a fake empty content is returned. - return new \RecursiveArrayIterator([]); - } else { - throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); - } + throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e); } }