Expand description
Atomic file write helpers for the EnvironmentStore.
The store mutates persistent state through the same pattern everywhere:
- Create a
NamedTempFilein the same directory as the target so the finalrenameis intra-filesystem (otherwise rename would fall back to copy+unlink and lose atomicity). - Write the bytes;
flush()+sync_all()so the data hits disk. persist(target)atomically renames over the existing target.- On Unix,
fsync()the parent directory so the rename itself is durable across power loss.
Callers that want to back up the current target before clobbering it should
call copy_to_backup first.
Enums§
Functions§
- atomic_
write_ bytes - Atomically write
bytestotarget, fsyncing the parent directory afterward. - atomic_
write_ json - Atomically write
valueas pretty-printed JSON (trailing newline) totarget. - copy_
to_ backup - If
targetexists, copy it to<backup_dir>/<target.file_name>.<rfc3339-utc>.bakand return the backup path. If it does not exist, returnOk(None).