mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Check if dirname exists
We only want to path normalize a string (and replace backslashes with forward slashes if on Windows) if it's actually a path. But checking if there's a path with that name doesn't work if the path is a substring of an actual path. Additionally check whether the dirname points to something on the file system. If it does, it's likely meant to be interpreted as a path.
This commit is contained in:
@@ -23,7 +23,9 @@ import sys
|
||||
# this normalizes Windows paths to use backslashes, we have to replace them
|
||||
# back to forward slashes.
|
||||
def normalize_if_path(s):
|
||||
if not os.path.exists(s):
|
||||
# Check dirname for cases like a file named `%t.out.txt`
|
||||
# There won't be a `%t` path, but we still want to match this path substring.
|
||||
if not os.path.exists(s) and not os.path.exists(os.path.dirname(s)):
|
||||
return s
|
||||
if platform.system() == "Windows":
|
||||
return os.path.abspath(s).replace('\\', '/')
|
||||
|
||||
Reference in New Issue
Block a user