Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/fromager/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,10 +883,11 @@ def scan_compiled_extensions(
elif suffix not in ignore_suffixes:
# Path.walk() lists symlinks to directories as filenames
# rather than dirnames, causing IsADirectoryError on open().
# Broken symlinks raise FileNotFoundError on open().
try:
with filepath.open("rb") as f:
header = f.read(_MAGIC_HEADERS_READ)
except IsADirectoryError:
except (IsADirectoryError, FileNotFoundError):
continue
if header.startswith(magic_headers):
relpath = filepath.relative_to(root_dir)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,11 @@ def test_scan_compiled_extensions(
assert matches == [pathlib.Path(filename)]
else:
assert matches == []


def test_scan_compiled_extensions_broken_symlink(tmp_path: pathlib.Path) -> None:
"""Verify broken symlinks are skipped without raising an error."""
broken_link = tmp_path / "broken_link"
broken_link.symlink_to(tmp_path / "nonexistent_target")
matches = sources.scan_compiled_extensions(tmp_path)
assert matches == []
Loading