Skip to content

Commit 04ddb8e

Browse files
authored
Foundation: use NT-style paths for CopyFileW (#4793)
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.
1 parent 7fc59bf commit 04ddb8e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Sources/Foundation/FileManager+Win32.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,13 @@ extension FileManager {
548548
}
549549

550550
internal func _copyRegularFile(atPath srcPath: String, toPath dstPath: String, variant: String = "Copy") throws {
551-
try FileManager.default._fileSystemRepresentation(withPath: srcPath, andPath: dstPath) {
552-
if !CopyFileW($0, $1, false) {
553-
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [srcPath, dstPath])
551+
try withNTPathRepresentation(of: srcPath) { wszSource in
552+
try withNTPathRepresentation(of: dstPath) { wszDestination in
553+
if !CopyFileW(wszSource, wszDestination, false) {
554+
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [srcPath, dstPath])
555+
}
556+
}
554557
}
555-
}
556558
}
557559

558560
internal func _copySymlink(atPath srcPath: String, toPath dstPath: String, variant: String = "Copy") throws {

0 commit comments

Comments
 (0)