Skip to content

Foundation: use NT-style paths for CopyFileW #4793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down