rust/library/std
Matthias Krüger 51df98ddb0
Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, r=ChrisDenton
Win: Use POSIX rename semantics for `std::fs::rename` if available

Windows 10 1601 introduced `FileRenameInfoEx` as well as `FILE_RENAME_FLAG_POSIX_SEMANTICS`, allowing for atomic renaming and renaming if the target file is has already been opened with `FILE_SHARE_DELETE`, in which case the file gets renamed on disk while the open file handle still refers to the old file, just like in POSIX. This resolves #123985, where atomic renaming proved difficult to impossible due to race conditions.

If `FileRenameInfoEx` isn't available due to missing support from the underlying filesystem or missing OS support, the renaming is retried with `FileRenameInfo`, which matches the behavior of `MoveFileEx`.

This PR also manually replicates parts of `MoveFileEx`'s internal logic, as reverse-engineered from the disassembly: If the source file is a reparse point and said reparse point is a mount point, the mount point itself gets renamed; otherwise the reparse point is resolved and the result renamed.

Notes:
- Currently, the `win7` target doesn't bother with `FileRenameInfoEx` at all; it's probably desirable to remove that special casing and try `FileRenameInfoEx` anyway if it doesn't exist, in case the binary is run on newer OS versions.

Fixes #123985
2024-12-21 22:16:02 +01:00
..
benches Reformat use declarations. 2024-07-29 08:26:52 +10:00
src Rollup merge of #131072 - Fulgen301:windows-rename-posix-semantics, r=ChrisDenton 2024-12-21 22:16:02 +01:00
tests Fix and undeprecate home_dir() 2024-11-04 03:06:09 +00:00
build.rs Enable f128 tests on all non-buggy platforms 🎉 2024-11-03 19:33:04 -06:00
Cargo.toml build: Update libc version 2024-12-19 10:08:29 +01:00