Skip to content

Commit 7411034

Browse files
committed
TSCBasic: improve TemporaryFile on Windows
Rather than using the ASCII version of the functions which prevent the use of unicode characters in the path. Given that `String` in Swift internally will deal with the encoding, this allows us to encode to UTF-16 and use the unicode version of the functions.
1 parent ede125c commit 7411034

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/TSCBasic/TemporaryFile.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ public func withTemporaryFile<Result>(
135135
let tempFile = try TemporaryFile(dir: dir, prefix: prefix, suffix: suffix)
136136
defer {
137137
if deleteOnClose {
138+
#if os(Windows)
139+
_ = tempFile.path.pathString.withCString(encodedAs: UTF16.self) {
140+
_wunlink($0)
141+
}
142+
#else
138143
unlink(tempFile.path.pathString)
144+
#endif
139145
}
140146
}
141147
return try body(tempFile)

0 commit comments

Comments
 (0)