From 30a1c1d107667183b60240b17549182068dc717b Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 18 Jun 2023 07:47:31 -0700 Subject: [PATCH] Foundation: Windows long file support in `FileManager.createDirectory` Adjust the `createDirectory` path on Windows to properly support long file paths. This helps improve the DocC test coverage on Windows. --- Sources/Foundation/FileManager+Win32.swift | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Foundation/FileManager+Win32.swift b/Sources/Foundation/FileManager+Win32.swift index d63bad245d..b456391319 100644 --- a/Sources/Foundation/FileManager+Win32.swift +++ b/Sources/Foundation/FileManager+Win32.swift @@ -269,20 +269,20 @@ extension FileManager { } } - try FileManager.default._fileSystemRepresentation(withPath: path) { fsr in - var saAttributes: SECURITY_ATTRIBUTES = - SECURITY_ATTRIBUTES(nLength: DWORD(MemoryLayout.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.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) } }