try to fix regression on Windows due to tempfiles semantics (#3601)

Until `perist()` is truly atomic also on Windows, and modelled
[after Git](https://github.com/git/git/blob/master/compat/mingw.c#L2159-L2209),
sans the retries, it seems to work to just perform ordinary writes.

Before going there though, we try to call `sync_all()` on Windows to truly
finish the operation. On Unix, a rename is already supposed to be atomic.
This commit is contained in:
Sebastian Thiel 2024-04-27 15:51:54 +02:00
parent 91d892882e
commit 4f58883bd4
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B

View File

@ -87,7 +87,12 @@ fn persist_tempfile(
to_path: impl AsRef<Path>,
) -> std::io::Result<()> {
match tempfile.persist(to_path) {
Ok(Some(_opened_file)) => Ok(()),
Ok(Some(_opened_file)) => {
// EXPERIMENT: Does this fix #3601?
#[cfg(windows)]
_opened_file.sync_all()?;
Ok(())
}
Ok(None) => unreachable!(
"BUG: a signal has caused the tempfile to be removed, but we didn't install a handler"
),