1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// (C) Copyright 2024- ECMWF and individual contributors.
//
// This software is licensed under the terms of the Apache Licence Version 2.0
// which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
// In applying this licence, ECMWF does not waive the privileges and immunities
// granted to it by virtue of its status as an intergovernmental organisation nor
// does it submit to any jurisdiction.
//! Crash-safe atomic file write.
//!
//! Thin wrapper around the [`atomicwrites`] crate. Isolating it in
//! one private module means the upstream dependency surface can be
//! swapped or vendored without touching the file store's logic.
//!
//! The atomic write pattern: write to a temp file in the same
//! directory, `fsync` the temp file, atomically `rename` over the
//! target, then `fsync` the parent directory. On Windows the rename
//! step uses `MoveFileExW` with `MOVEFILE_WRITE_THROUGH` and
//! `MOVEFILE_REPLACE_EXISTING`.
//!
//! These calls are synchronous (blocking). Async callers must wrap
//! them in [`tokio::task::spawn_blocking`].
use io;
use Write;
use Path;
use ;
/// Write `bytes` to `path` atomically and crash-safely.
///
/// # Errors
///
/// Returns the underlying [`io::Error`] from any I/O step (temp-file
/// creation, write, fsync, or rename).
pub