Skip to content

Commit 324bf79

Browse files
authored
Bug fix / workaround in lib/spack/spack/llnl/util/filesystem.py: prevent recursively traversing the root filesystem (#576)
1 parent 45341d8 commit 324bf79

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/spack/spack/llnl/util/filesystem.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,15 @@ def _dedupe_files(paths: List[str]) -> List[str]:
18121812
return unique_files
18131813

18141814

1815+
def _is_root_directory(curr_dir: str):
1816+
"""
1817+
Check if the given directory is the top-level root directory.
1818+
Works on Windows, macOS, and Linux.
1819+
"""
1820+
path = pathlib.Path(curr_dir).resolve()
1821+
return path == path.anchor or path.parent == path
1822+
1823+
18151824
def _find_max_depth(
18161825
roots: Sequence[Path], globs: Sequence[str], max_depth: int = sys.maxsize
18171826
) -> List[str]:
@@ -1846,6 +1855,9 @@ def _find_max_depth(
18461855

18471856
while dir_queue:
18481857
depth, curr_dir = dir_queue.pop()
1858+
# Never traverse root recursively
1859+
if _is_root_directory(curr_dir):
1860+
continue
18491861
try:
18501862
dir_iter = os.scandir(curr_dir)
18511863
except OSError as e:

0 commit comments

Comments
 (0)