Skip to content

Commit 7e77653

Browse files
committed
Fix bugs on Windows
1 parent f8a8752 commit 7e77653

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,19 @@ public final class Process {
352352
currentWorkingDirectory: cwdOpt
353353
)
354354
#if os(Windows)
355-
var searchPaths = [String]()
356-
let buffer = UnsafeMutablePointer<String>.allocate(capacity: 260)
355+
var searchPaths = Array<AbsolutePath>()
356+
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
357357

358358
// The 32-bit Windows system directory
359-
GetSystemDirectoryW(buffer, 260)
360-
searchPaths += buffer.pointee
359+
GetSystemDirectoryW(&buffer, .init(MAX_PATH + 1))
360+
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
361361

362362
// The 16-bit Windows system directory
363-
searchPaths += "\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"
363+
searchPaths.append(AbsolutePath("\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"))
364364

365365
// The Windows directory
366-
GetWindowsDirectoryW(buffer, 260)
367-
searchPaths += buffer.pointee
366+
GetWindowsDirectoryW(&buffer, .init(MAX_PATH + 1))
367+
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
368368

369369
searchPaths.append(contentsOf: envSearchPaths)
370370
#else

Sources/TSCBasic/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public func lookupExecutablePath(
9999
return nil
100100
}
101101
let isPath = value.contains("\\")
102-
if !isPath && value.contains(".") {
102+
if !isPath && !value.contains(".") {
103103
value.append(executableFileSuffix)
104104
}
105105
#else

Tests/TSCBasicTests/TemporaryFileTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class TemporaryFileTests: XCTestCase {
137137
XCTAssertFalse(localFileSystem.isDirectory(pathTwo))
138138
}
139139

140+
#if !os(Windows) // `fileDescriptor` is currently unavailable in Windows
140141
/// Check that the temporary file doesn't leak file descriptors.
141142
func testLeaks() throws {
142143
// We check this by testing that we get back the same FD after a
@@ -152,4 +153,5 @@ class TemporaryFileTests: XCTestCase {
152153
XCTAssertEqual(initialFD, endFD)
153154
#endif
154155
}
156+
#endif
155157
}

0 commit comments

Comments
 (0)