Skip to main content

write_atomic

Function write_atomic 

Source
pub fn write_atomic(path: &Path, contents: &[u8]) -> Result<()>
Expand description

Atomically write contents to path by writing a sibling temp file and renaming it into place. rename(2) on the same filesystem is atomic, so a crash or execve mid-write leaves either the previous file or the fully-written new one — never a truncated/0-byte file. Creates the parent directory if missing.

This is the write counterpart to read_optional_text and the fix for an interrupted write (e.g. an auto_install_reexec recycle killed mid-write) leaving a 0-byte controller-state file that then wedges every future read.