Skip to content

Commit

Permalink
Foundation: Windows long file support in FileManager.createDirectory (
Browse files Browse the repository at this point in the history
#4771)

Adjust the `createDirectory` path on Windows to properly support long
file paths.  This helps improve the DocC test coverage on Windows.
  • Loading branch information
compnerd committed Jun 19, 2023
1 parent 97a604c commit ba1e4f6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,20 @@ extension FileManager {
}
}

try FileManager.default._fileSystemRepresentation(withPath: path) { fsr in
var saAttributes: SECURITY_ATTRIBUTES =
SECURITY_ATTRIBUTES(nLength: DWORD(MemoryLayout<SECURITY_ATTRIBUTES>.size),
lpSecurityDescriptor: nil,
bInheritHandle: false)
try withUnsafeMutablePointer(to: &saAttributes) {
if !CreateDirectoryW(fsr, $0) {
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
try withNTPathRepresentation(of: path) { wszPath in
var saAttributes: SECURITY_ATTRIBUTES =
SECURITY_ATTRIBUTES(nLength: DWORD(MemoryLayout<SECURITY_ATTRIBUTES>.size),
lpSecurityDescriptor: nil,
bInheritHandle: false)
try withUnsafeMutablePointer(to: &saAttributes) { pSecurityAttributes in
guard CreateDirectoryW(wszPath, pSecurityAttributes) else {
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
}
}
}
}

if let attr = attributes {
try self.setAttributes(attr, ofItemAtPath: path)
}
if let attributes {
try self.setAttributes(attributes, ofItemAtPath: path)
}
}

Expand Down

0 comments on commit ba1e4f6

Please sign in to comment.