diff --git a/Sources/Foundation/FileManager+POSIX.swift b/Sources/Foundation/FileManager+POSIX.swift index a400abb830..cf7573ba14 100644 --- a/Sources/Foundation/FileManager+POSIX.swift +++ b/Sources/Foundation/FileManager+POSIX.swift @@ -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)) diff --git a/Sources/Foundation/FileManager+Win32.swift b/Sources/Foundation/FileManager+Win32.swift index 8fea257006..6d325c79cc 100644 --- a/Sources/Foundation/FileManager+Win32.swift +++ b/Sources/Foundation/FileManager+Win32.swift @@ -476,7 +476,7 @@ 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) { + if !CopyFileW($0, $1, true) { throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [srcPath, dstPath]) } }