Changes after comments from Saleem.

Use idiomatic Swift notation, not `Optional<Bool>`.

Prefer Win32 APIs to UCRT APIs.

rdar://125087707
This commit is contained in:
Alastair Houghton authored and Guillaume Lessard committed 2024-10-14 15:59:36 -07:00
1 parent 85de4e51e2
commit 4cafcc96f6
3 files changed
+17 -7

No files matched your search

+2 -3
View File
@@ -29,8 +29,7 @@ internal func getTemporaryDirectory() throws -> FilePath {
capacity: Int(MAX_PATH) + 1) {
buffer in
let count = GetTempPath2W(DWORD(buffer.count), buffer.baseAddress)
if count == 0 {
guard GetTempPath2W(DWORD(buffer.count), buffer.baseAddress) != 0 else {
throw Errno(windowsError: GetLastError())
}
@@ -116,7 +115,7 @@ internal func getTemporaryDirectory() throws -> FilePath {
while true {
let path: FilePath? = withUnsafeTemporaryAllocation(
of: CInterop.PlatformChar.self,
capacity: 1024) { buffer in
capacity: capacity) { buffer in
let len = system_confstr(SYSTEM_CS_DARWIN_USER_TEMP_DIR,
buffer.baseAddress!,
buffer.count)
+2 -2
View File
@@ -110,7 +110,7 @@ private var contextualMockingEnabled: Bool {
extension MockingDriver {
internal static var enabled: Bool { mockingEnabled }
internal static var forceWindowsPaths: Optional<Bool> {
internal static var forceWindowsPaths: Bool? {
currentMockingDriver?.forceWindowsSyntaxForPaths
}
}
@@ -128,7 +128,7 @@ internal var mockingEnabled: Bool {
}
@inline(__always)
internal var forceWindowsPaths: Optional<Bool> {
internal var forceWindowsPaths: Bool? {
#if !ENABLE_MOCKING
return false
#else
@@ -160,14 +160,25 @@ internal func mkdir(
_ path: UnsafePointer<CInterop.PlatformChar>,
_ mode: CInterop.Mode
) -> CInt {
return _wmkdir(path)
// TODO: Read/write permissions (these need mapping to a SECURITY_DESCRIPTOR).
if !CreateDirectoryW(path, nil) {
ucrt._set_errno(mapWindowsErrorToErrno(GetLastError()))
return -1
}
return 0;
}
@inline(__always)
internal func rmdir(
_ path: UnsafePointer<CInterop.PlatformChar>
) -> CInt {
return _wrmdir(path)
if !RemoveDirectoryW(path) {
ucrt._set_errno(mapWindowsErrorToErrno(GetLastError()))
return -1
}
return 0;
}
@usableFromInline