Skip to content

Commit

Permalink
Fix problems on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Dec 21, 2020
1 parent 1d261e1 commit fe54c4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,19 @@ public final class Process: ObjectIdentifierProtocol {
currentWorkingDirectory: localFileSystem.currentWorkingDirectory
)
#if os(Windows)
var searchPaths = [String]()
let buffer = UnsafeMutablePointer<String>.allocate(capacity: 260)
var searchPaths = Array<AbsolutePath>()
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))

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

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

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

searchPaths.append(contentsOf: envSearchPaths)
#else
Expand Down
2 changes: 2 additions & 0 deletions Tests/TSCBasicTests/TemporaryFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TemporaryFileTests: XCTestCase {
XCTAssertFalse(localFileSystem.isDirectory(pathTwo))
}

#if !os(Windows) // `fileDescriptor` is currently unavailable in Windows
/// Check that the temporary file doesn't leak file descriptors.
func testLeaks() throws {
// We check this by testing that we get back the same FD after a
Expand All @@ -150,4 +151,5 @@ class TemporaryFileTests: XCTestCase {
let endFD = try Int(withTemporaryFile { return $0.fileHandle.fileDescriptor })
XCTAssertEqual(initialFD, endFD)
}
#endif
}

0 comments on commit fe54c4c

Please sign in to comment.