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
use Path;
use crate;
use cratepersistence;
use crateMessageEnvelope;
/// Atomically replace one mailbox JSONL file from fully serialized records.
///
/// ATM serializes every envelope into one temp file, fsyncs that temp file, and
/// then performs same-filesystem replacement through the shared persistence
/// helper. On Linux, a successful return means the file contents and renamed
/// directory entry were durably published after the parent-directory fsync. On
/// macOS, ATM performs the same parent-directory sync call, but APFS durability
/// semantics may still differ from Linux after power loss. On Windows, the
/// shared helper returns `Ok(())` after temp-file fsync plus rename without an
/// additional parent-directory sync because the standard library does not
/// expose a portable directory-sync operation there.
///
/// # Errors
///
/// Returns [`AtmError`] with
/// [`crate::error_codes::AtmErrorCode::MailboxWriteFailed`] when message
/// serialization fails or the mailbox temp-file write, fsync, rename, or
/// parent-directory durability step cannot be completed.