Skip to content

Commit 24b2086

Browse files
committed
added Finder::ignoreUnreadableDirs()
1 parent 307b953 commit 24b2086

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Utils/Finder.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Finder implements \IteratorAggregate
3131
private FinderBatch $batch;
3232
private bool $selfFirst = true;
3333
private int $maxDepth = -1;
34+
private bool $ignoreUnreadableDirs = true;
3435

3536

3637
public function __construct()
@@ -160,6 +161,13 @@ public function childFirst(): static
160161
}
161162

162163

164+
public function ignoreUnreadableDirs(bool $state = true): static
165+
{
166+
$this->ignoreUnreadableDirs = $state;
167+
return $this;
168+
}
169+
170+
163171
/**
164172
* Starts defining a new search group.
165173
*/
@@ -305,7 +313,16 @@ private function traverseDir(string $dir, array $searches, array $subDirs = []):
305313
throw new Nette\InvalidStateException("Directory '$dir' not found.");
306314
}
307315

308-
$items = new \FilesystemIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME);
316+
try {
317+
$items = new \FilesystemIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME);
318+
} catch (\UnexpectedValueException $e) {
319+
if ($this->ignoreUnreadableDirs) {
320+
return;
321+
} else {
322+
throw new Nette\InvalidStateException($e->getMessage());
323+
}
324+
}
325+
309326
$relativePath = implode(DIRECTORY_SEPARATOR, $subDirs);
310327

311328
foreach ($items as $pathName) {

0 commit comments

Comments
 (0)