Skip to main content

Module atomic

Module atomic 

Source
Expand description

Atomic in-place file rewrite: sibling tempfile + atomic rename.

Per AD-001/AD-014: write to a sibling tempfile in target.parent(), then call NamedTempFile::persist(target) (which wraps std::fs::rename, with Windows FileRenameInfoEx+POSIX semantics where available). Mid-write failures leave the original target byte-identical to its prior state (FR-006).

Mode preservation on Unix (FR-008): if the target exists as a regular non-symlink file, capture its st_mode and reapply to the tempfile before persist. Read-only attribute preservation on Windows (FR-009): same idea for Permissions::readonly().

Append mode (-a, FR-004): if requested AND the target exists, copy its current bytes to the tempfile first, then write the incoming buffer. Missing target with -a is a no-op per FR-005.

Functions§

write_atomic
Write buffer to target atomically. See module docs.