Skip to content
Draft
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
12 changes: 12 additions & 0 deletions lib/spack/spack/llnl/util/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,15 @@ def _dedupe_files(paths: List[str]) -> List[str]:
return unique_files


def _is_root_directory(curr_dir: str):
"""
Check if the given directory is the top-level root directory.
Works on Windows, macOS, and Linux.
"""
path = pathlib.Path(curr_dir).resolve()
return path == path.anchor or path.parent == path


def _find_max_depth(
roots: Sequence[Path], globs: Sequence[str], max_depth: int = sys.maxsize
) -> List[str]:
Expand Down Expand Up @@ -1846,6 +1855,9 @@ def _find_max_depth(

while dir_queue:
depth, curr_dir = dir_queue.pop()
# Never traverse root recursively
if _is_root_directory(curr_dir):
continue
try:
dir_iter = os.scandir(curr_dir)
except OSError as e:
Expand Down
Loading