fix nativeToUnixPath (#18501)

This commit is contained in:
Timothee Cour 2021-07-16 22:54:47 -07:00 • committed by GitHub
commit 923a1c6ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View file

@ -45,10 +45,15 @@ iterator walkDirRecFilter*(dir: string, follow: proc(entry: PathEntry): bool = n
proc nativeToUnixPath*(path: string): string =
# pending https://github.com/nim-lang/Nim/pull/13265
doAssert not path.isAbsolute # not implemented here; absolute files need more care for the drive
result = path
when defined(windows):
if path.len >= 2 and path[0] in {'a'..'z', 'A'..'Z'} and path[1] == ':':
result[0] = '/'
result[1] = path[0]
if path.len > 2 and path[2] != '\\':
doAssert false, "paths like `C:foo` are currently unsupported, path: " & path
when DirSep == '\\':
result = replace(path, '\\', '/')
else: result = path
result = replace(result, '\\', '/')
when isMainModule:
import sugar