Skip to content

Commit ba1e4f6

Browse files
authored
Foundation: Windows long file support in FileManager.createDirectory (#4771)
Adjust the `createDirectory` path on Windows to properly support long file paths. This helps improve the DocC test coverage on Windows.
1 parent 97a604c commit ba1e4f6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Sources/Foundation/FileManager+Win32.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,20 @@ extension FileManager {
269269
}
270270
}
271271

272-
try FileManager.default._fileSystemRepresentation(withPath: path) { fsr in
273-
var saAttributes: SECURITY_ATTRIBUTES =
274-
SECURITY_ATTRIBUTES(nLength: DWORD(MemoryLayout<SECURITY_ATTRIBUTES>.size),
275-
lpSecurityDescriptor: nil,
276-
bInheritHandle: false)
277-
try withUnsafeMutablePointer(to: &saAttributes) {
278-
if !CreateDirectoryW(fsr, $0) {
279-
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
272+
try withNTPathRepresentation(of: path) { wszPath in
273+
var saAttributes: SECURITY_ATTRIBUTES =
274+
SECURITY_ATTRIBUTES(nLength: DWORD(MemoryLayout<SECURITY_ATTRIBUTES>.size),
275+
lpSecurityDescriptor: nil,
276+
bInheritHandle: false)
277+
try withUnsafeMutablePointer(to: &saAttributes) { pSecurityAttributes in
278+
guard CreateDirectoryW(wszPath, pSecurityAttributes) else {
279+
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
280+
}
280281
}
281-
}
282+
}
282283

283-
if let attr = attributes {
284-
try self.setAttributes(attr, ofItemAtPath: path)
285-
}
284+
if let attributes {
285+
try self.setAttributes(attributes, ofItemAtPath: path)
286286
}
287287
}
288288

0 commit comments

Comments
 (0)