Skip to content

Conversation

@gwynne
Copy link
Contributor

@gwynne gwynne commented Oct 2, 2023

This is a cherry-pick of #4821 to 5.9.1.

On Apple platforms, the FileManager APIs copyItem(atPath:toPath:) and copyItem(at:to:) refuse to overwrite the destination file (or link, or directory) if it already exists; this behavior is even explicitly documented. And indeed, any such attempt results in a fileWriteFileExists error.

However, on Linux and Windows, the destination is silently overwritten. This PR changes that behavior to match what's documented. On POSIX platforms, this is accomplished by adding the O_EXCL flag to the relevant open(2) call, which results in an EEXIST errno if the path already exists. For Windows, the bFailIfExists parameter of CopyFileW() is changed to true.

Fixes #3368

@compnerd
Copy link
Member

compnerd commented Oct 2, 2023

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Oct 2, 2023

@swift-ci please test macOS platform

@compnerd
Copy link
Member

compnerd commented Oct 7, 2023

@swift-ci please test macOS platform

@gwynne
Copy link
Contributor Author

gwynne commented Oct 30, 2023

This didn't make it into 5.9.1, closing

@gwynne gwynne closed this Oct 30, 2023
@gwynne gwynne deleted the gwynne/fix-linux-copyitem-overwrite-5.9.1 branch October 30, 2023 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants