Merge pull request #2002 from flesueur/master
Improve performance of `path_to_filesystem()`
This commit is contained in:
@@ -282,14 +282,11 @@ def path_to_filesystem(root: str, sane_path: str) -> str:
|
|||||||
for part in parts:
|
for part in parts:
|
||||||
if not is_safe_filesystem_path_component(part):
|
if not is_safe_filesystem_path_component(part):
|
||||||
raise UnsafePathError(part)
|
raise UnsafePathError(part)
|
||||||
safe_path_parent = safe_path
|
|
||||||
safe_path = os.path.join(safe_path, part)
|
safe_path = os.path.join(safe_path, part)
|
||||||
# Check for conflicting files (e.g. case-insensitive file systems
|
# Check for conflicting files (e.g. case-insensitive file systems
|
||||||
# or short names on Windows file systems)
|
# or short names on Windows file systems)
|
||||||
if os.path.lexists(safe_path):
|
if (os.path.lexists(safe_path) and not os.path.realpath(safe_path).endswith(part)):
|
||||||
with os.scandir(safe_path_parent) as entries:
|
raise CollidingPathError(part)
|
||||||
if part not in (e.name for e in entries):
|
|
||||||
raise CollidingPathError(part)
|
|
||||||
return safe_path
|
return safe_path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user