Skip broken directory entries during discovery
This commit is contained in:
@@ -33,10 +33,28 @@ def _discover_root(
|
||||
extensions: set[str],
|
||||
discovered: list[FileCandidate],
|
||||
) -> None:
|
||||
entries = sorted(root.iterdir(), key=lambda item: (not item.is_file(), item.name.lower()))
|
||||
entries: list[tuple[Path, bool]] = []
|
||||
try:
|
||||
for entry in root.iterdir():
|
||||
try:
|
||||
entries.append((entry, entry.is_file()))
|
||||
except OSError:
|
||||
continue
|
||||
except OSError:
|
||||
return
|
||||
|
||||
entries.sort(key=lambda item: (not item[1], item[0].name.lower()))
|
||||
|
||||
for entry, is_file in entries:
|
||||
if not is_file:
|
||||
try:
|
||||
is_dir = entry.is_dir()
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
if not is_dir:
|
||||
continue
|
||||
|
||||
for entry in entries:
|
||||
if entry.is_dir():
|
||||
if recursive:
|
||||
_discover_root(
|
||||
root=entry,
|
||||
@@ -50,7 +68,11 @@ def _discover_root(
|
||||
if extension not in extensions:
|
||||
continue
|
||||
|
||||
stat = entry.stat()
|
||||
try:
|
||||
stat = entry.stat()
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
discovered.append(
|
||||
FileCandidate(
|
||||
path=entry,
|
||||
|
||||
Reference in New Issue
Block a user