Skip to content

Conversation

@gwynne
Copy link
Contributor

@gwynne gwynne commented Aug 7, 2023

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

gwynne added a commit to vapor/api-docs that referenced this pull request Aug 7, 2023
gwynne added a commit to vapor/api-docs that referenced this pull request Aug 7, 2023
* Add some icons
* Pretty up generate-package-api-docs.swift a bit
* Work around swiftlang/swift-corelibs-foundation#4808
@compnerd
Copy link
Member

compnerd commented Aug 7, 2023

@swift-ci please test

@phausler phausler requested review from iCharlesHu and parkera August 8, 2023 15:39
@compnerd
Copy link
Member

@swift-ci please test macOS platform

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.

[SR-11963] FileManager.copyItem doesn't fail when there already is an item at destination path

3 participants