Skip to content

Commit

Permalink
added Finder::ignoreUnreadableDirs()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 4, 2022
1 parent ff07aaa commit d8f1495
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Utils/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Finder implements \IteratorAggregate
private FinderBatch $batch;
private bool $selfFirst = true;
private int $maxDepth = -1;
private bool $ignoreUnreadableDirs = true;


public function __construct()
Expand Down Expand Up @@ -160,6 +161,13 @@ public function childFirst(): static
}


public function ignoreUnreadableDirs(bool $state = true): static
{
$this->ignoreUnreadableDirs = $state;
return $this;
}


/**
* Starts defining a new search group.
*/
Expand Down Expand Up @@ -306,7 +314,16 @@ private function traverseDir(string $dir, array $searches, array $subDirs = []):
throw new Nette\InvalidStateException("Directory '$dir' not found.");
}

$items = new \FilesystemIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME);
try {
$items = new \FilesystemIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME);
} catch (\UnexpectedValueException $e) {
if ($this->ignoreUnreadableDirs) {
return;
} else {
throw new Nette\InvalidStateException($e->getMessage());
}
}

$relativePath = implode(DIRECTORY_SEPARATOR, $subDirs);

foreach ($items as $pathName) {
Expand Down

0 comments on commit d8f1495

Please sign in to comment.