Skip to content

[5.6] TSCBasic: rework relative path construction on Windows (#298) #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Sources/TSCBasic/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,29 @@ public struct AbsolutePath: Hashable {
if PathImpl(string: str).isAbsolute {
self.init(str)
} else {
#if os(Windows)
var joined: PWSTR!
_ = basePath._impl.string.withCString(encodedAs: UTF16.self) { base in
str.withCString(encodedAs: UTF16.self) { path in
PathAllocCombine(base, path, ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue), &joined)
}
}
defer { LocalFree(joined) }

let buffer: UnsafePointer<Int8> =
String(decodingCString: joined, as: UTF16.self).fileSystemRepresentation
defer { buffer.deallocate() }

var canonical: PWSTR!
_ = String(cString: buffer).withCString(encodedAs: UTF16.self) {
PathAllocCanonicalize($0, ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue), &canonical)
}
defer { LocalFree(canonical) }

self.init(String(decodingCString: canonical, as: UTF16.self))
#else
self.init(basePath, RelativePath(str))
#endif
}
}

Expand Down