Skip to content

Commit ae65fdb

Browse files
authored
Merge pull request #1087 from andre-motta/fix/scan-compiled-extensions-broken-symlinks
fix(sources): catch FileNotFoundError for broken symlinks
2 parents 58b08db + 9589c5b commit ae65fdb

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/fromager/sources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,11 @@ def scan_compiled_extensions(
883883
elif suffix not in ignore_suffixes:
884884
# Path.walk() lists symlinks to directories as filenames
885885
# rather than dirnames, causing IsADirectoryError on open().
886+
# Broken symlinks raise FileNotFoundError on open().
886887
try:
887888
with filepath.open("rb") as f:
888889
header = f.read(_MAGIC_HEADERS_READ)
889-
except IsADirectoryError:
890+
except (IsADirectoryError, FileNotFoundError):
890891
continue
891892
if header.startswith(magic_headers):
892893
relpath = filepath.relative_to(root_dir)

tests/test_sources.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,11 @@ def test_scan_compiled_extensions(
285285
assert matches == [pathlib.Path(filename)]
286286
else:
287287
assert matches == []
288+
289+
290+
def test_scan_compiled_extensions_broken_symlink(tmp_path: pathlib.Path) -> None:
291+
"""Verify broken symlinks are skipped without raising an error."""
292+
broken_link = tmp_path / "broken_link"
293+
broken_link.symlink_to(tmp_path / "nonexistent_target")
294+
matches = sources.scan_compiled_extensions(tmp_path)
295+
assert matches == []

0 commit comments

Comments
 (0)