Skip to content

Commit d8f1495

Browse files
committed
added Finder::ignoreUnreadableDirs()
1 parent ff07aaa commit d8f1495

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
*/
@@ -306,7 +314,16 @@ private function traverseDir(string $dir, array $searches, array $subDirs = []):
306314
throw new Nette\InvalidStateException("Directory '$dir' not found.");
307315
}
308316

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

312329
foreach ($items as $pathName) {

0 commit comments

Comments
 (0)