From 4dc55fe61b53946bdb4b364eff4270ddc9c7f418 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 10 Jul 2023 13:31:45 -0700 Subject: [PATCH] Foundation: use NT-style paths for `CopyFileW` When invoking `_copyRegularFile` ensure that we use the NT-style path to enable long file names on all targets. This allows copying directories that contain a deeply nested path. --- Sources/Foundation/FileManager+Win32.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/Foundation/FileManager+Win32.swift b/Sources/Foundation/FileManager+Win32.swift index 83c38c63e5..d19ece90e7 100644 --- a/Sources/Foundation/FileManager+Win32.swift +++ b/Sources/Foundation/FileManager+Win32.swift @@ -548,11 +548,13 @@ extension FileManager { } internal func _copyRegularFile(atPath srcPath: String, toPath dstPath: String, variant: String = "Copy") throws { - try FileManager.default._fileSystemRepresentation(withPath: srcPath, andPath: dstPath) { - if !CopyFileW($0, $1, false) { - throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [srcPath, dstPath]) + try withNTPathRepresentation(of: srcPath) { wszSource in + try withNTPathRepresentation(of: dstPath) { wszDestination in + if !CopyFileW(wszSource, wszDestination, false) { + throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [srcPath, dstPath]) + } + } } - } } internal func _copySymlink(atPath srcPath: String, toPath dstPath: String, variant: String = "Copy") throws {