improve path_to_filesystem() performance

This commit is contained in:
Francois Lesueur
2026-02-27 15:04:00 +01:00
parent c72347c715
commit d3018a4c06

View File

@@ -286,10 +286,9 @@ def path_to_filesystem(root: str, sane_path: str) -> str:
safe_path = os.path.join(safe_path, part)
# Check for conflicting files (e.g. case-insensitive file systems
# or short names on Windows file systems)
if os.path.lexists(safe_path):
with os.scandir(safe_path_parent) as entries:
if part not in (e.name for e in entries):
raise CollidingPathError(part)
if (os.path.lexists(safe_path) and
not os.path.realpath(safe_path).endswith(part)):
raise CollidingPathError(part)
return safe_path