Skip to content

Commit a740351

Browse files
committed
Changes after comments from Saleem.
Use idiomatic Swift notation, not `Optional<Bool>`. Prefer Win32 APIs to UCRT APIs. rdar://125087707
1 parent e858f1a commit a740351

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Sources/System/FilePath/FilePathTemp.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ internal func getTemporaryDirectory() throws -> FilePath {
2929
capacity: Int(MAX_PATH) + 1) {
3030
buffer in
3131

32-
let count = GetTempPath2W(DWORD(buffer.count), buffer.baseAddress)
33-
if count == 0 {
32+
guard let count = GetTempPath2W(DWORD(buffer.count), buffer.baseAddress),
33+
count != 0 else {
3434
throw Errno(windowsError: GetLastError())
3535
}
3636

@@ -116,7 +116,7 @@ internal func getTemporaryDirectory() throws -> FilePath {
116116
while true {
117117
let path: FilePath? = withUnsafeTemporaryAllocation(
118118
of: CInterop.PlatformChar.self,
119-
capacity: 1024) { buffer in
119+
capacity: capacity) { buffer in
120120
let len = system_confstr(SYSTEM_CS_DARWIN_USER_TEMP_DIR,
121121
buffer.baseAddress!,
122122
buffer.count)

Sources/System/Internals/Mocking.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private var contextualMockingEnabled: Bool {
110110
extension MockingDriver {
111111
internal static var enabled: Bool { mockingEnabled }
112112

113-
internal static var forceWindowsPaths: Optional<Bool> {
113+
internal static var forceWindowsPaths: Bool? {
114114
currentMockingDriver?.forceWindowsSyntaxForPaths
115115
}
116116
}
@@ -128,7 +128,7 @@ internal var mockingEnabled: Bool {
128128
}
129129

130130
@inline(__always)
131-
internal var forceWindowsPaths: Optional<Bool> {
131+
internal var forceWindowsPaths: Bool? {
132132
#if !ENABLE_MOCKING
133133
return false
134134
#else

Sources/System/Internals/WindowsSyscallAdapters.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,25 @@ internal func mkdir(
160160
_ path: UnsafePointer<CInterop.PlatformChar>,
161161
_ mode: CInterop.Mode
162162
) -> CInt {
163-
return _wmkdir(path)
163+
// TODO: Read/write permissions (these need mapping to a SECURITY_DESCRIPTOR).
164+
if !CreateDirectoryW(path, nil) {
165+
ucrt._set_errno(mapWindowsErrorToErrno(GetLastError()))
166+
return -1
167+
}
168+
169+
return 0;
164170
}
165171

166172
@inline(__always)
167173
internal func rmdir(
168174
_ path: UnsafePointer<CInterop.PlatformChar>
169175
) -> CInt {
170-
return _wrmdir(path)
176+
if !RemoveDirectoryW(path) {
177+
ucrt._set_errno(mapWindowsErrorToErrno(GetLastError()))
178+
return -1
179+
}
180+
181+
return 0;
171182
}
172183

173184
@usableFromInline

0 commit comments

Comments
 (0)