Skip to content

Commit

Permalink
Merge pull request #4825 from gwynne/gwynne/fix-linux-copyitem-overwr…
Browse files Browse the repository at this point in the history
…ite-5.10

[5.10] Cherry-pick Fix divergent overwrite behavior of FileManager.copyItem(at:to:) on Linux and Windows
  • Loading branch information
compnerd committed Sep 29, 2023
2 parents 595f137 + 84adf64 commit 50a77b5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Foundation/FileManager+POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ extension FileManager {
}
defer { close(srcfd) }

let dstfd = open(dstRep, O_WRONLY | O_CREAT | O_TRUNC, 0o666)
let dstfd = open(dstRep, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC, 0o666)
guard dstfd >= 0 else {
throw _NSErrorWithErrno(errno, reading: false, path: dstPath,
extraUserInfo: extraErrorInfo(srcPath: srcPath, dstPath: dstPath, userVariant: variant))
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ extension FileManager {
internal func _copyRegularFile(atPath srcPath: String, toPath dstPath: String, variant: String = "Copy") throws {
try withNTPathRepresentation(of: srcPath) { wszSource in
try withNTPathRepresentation(of: dstPath) { wszDestination in
if !CopyFileW(wszSource, wszDestination, false) {
if !CopyFileW(wszSource, wszDestination, true) {
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [srcPath, dstPath])
}
}
Expand Down

0 comments on commit 50a77b5

Please sign in to comment.