Skip broken directory entries during discovery

This commit is contained in:
kim
2026-03-30 13:34:03 +08:00
parent 76fee612f5
commit cd4965f46a
2 changed files with 67 additions and 4 deletions
+26 -4
View File
@@ -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,