Skip to content

Remove claim of atomicity from Copy #11505

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion xml/System.IO/File.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3656,7 +3656,7 @@ Note that if you attempt to replace a file by moving a file of the same name int

- In .NET Core 3.0 and later versions, you can call <xref:System.IO.File.Move(System.String,System.String,System.Boolean)> setting the parameter `overwrite` to `true`, which will replace the file if it exists.

- In all .NET versions, you can call <xref:System.IO.File.Copy(System.String,System.String,System.Boolean)> to copy with overwrite, then call `Delete` to remove the excess source file. This strategy is advisable if the file being copied is small, and you are looking for an "atomic" file operation. If you `Delete` the file first, and the system or program crashes, the destination file will no longer exist.
- In all .NET versions, you can call <xref:System.IO.File.Copy(System.String,System.String,System.Boolean)> to copy with overwrite, then call `Delete` to remove the excess source file. This strategy is not atomic, because a system or program crash during the `Copy` may leave a partially-written destination file, but it will ensure a (possibly incomplete) file always exists at the destination.

- In all .NET versions, you can call <xref:System.IO.File.Delete(System.String)> before calling `Move`, which will only delete the file if it exists.

Expand Down