Add an io::fsync module with a per-OS split (posix/windows) mirroring the writeback_file convention, replacing two duplicated dir-fsync copies: - dir(): POSIX directory fsync; a no-op on Windows, where std cannot open a directory as a File and the failed open logged a spurious warning on every mapfile write. - file_durable(): opens the target read+write before sync_all so the flush succeeds on Windows, where FlushFileBuffers rejects a read-only handle with ERROR_ACCESS_DENIED. Point the mapfile writer at the shared dir() helper.
19 lines
644 B
Rust
19 lines
644 B
Rust
//! POSIX directory-fsync. Active on unix and any non-Windows fallback target
|
|
//! (BSD, illumos, …) — all share the same `File::open(dir).sync_all()`
|
|
//! semantics. The Windows no-op lives in the sibling `windows` module.
|
|
|
|
use std::path::Path;
|
|
|
|
pub(super) fn fsync_dir(dir: &Path) {
|
|
match std::fs::File::open(dir) {
|
|
Ok(f) => {
|
|
if let Err(e) = f.sync_all() {
|
|
tracing::warn!(path = %dir.display(), error = %e, "failed to fsync directory");
|
|
}
|
|
}
|
|
Err(e) => {
|
|
tracing::warn!(path = %dir.display(), error = %e, "could not open directory to fsync");
|
|
}
|
|
}
|
|
}
|