@@ -39,6 +39,7 @@ class Finder implements \IteratorAggregate
3939 private array $ descentFilters = [];
4040 private bool $ childFirst = false ;
4141 private int $ maxDepth = -1 ;
42+ private bool $ ignoreUnreadableDirs = true ;
4243
4344
4445 /**
@@ -152,6 +153,16 @@ public function childFirst(bool $state = true): static
152153 }
153154
154155
156+ /**
157+ * Ignores unreadable directories. By default, this is enabled.
158+ */
159+ public function ignoreUnreadableDirs (bool $ state = true ): static
160+ {
161+ $ this ->ignoreUnreadableDirs = $ state ;
162+ return $ this ;
163+ }
164+
165+
155166 /********************* filtering ****************d*g**/
156167
157168
@@ -287,10 +298,19 @@ private function traverseDir(string $dir, array $searches, array $subdirs = []):
287298 throw new Nette \InvalidStateException ("Directory ' $ dir' not found. " );
288299 }
289300
290- $ pathNames = new \FilesystemIterator ($ dir , \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::UNIX_PATHS );
291- $ relativePath = implode ('/ ' , $ subdirs );
301+ try {
302+ $ pathNames = new \FilesystemIterator ($ dir , \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::UNIX_PATHS );
303+ } catch (\UnexpectedValueException $ e ) {
304+ if ($ this ->ignoreUnreadableDirs ) {
305+ return ;
306+ } else {
307+ throw new Nette \InvalidStateException ($ e ->getMessage ());
308+ }
309+ }
292310 $ absolute = FileSystem::isAbsolute ($ dir );
293311
312+ $ relativePath = implode (DIRECTORY_SEPARATOR , $ subdirs );
313+
294314 foreach ($ pathNames as $ pathName ) {
295315 if (!$ absolute ) {
296316 $ pathName = preg_replace ('~\.?/~A ' , '' , $ pathName );
0 commit comments