Skip to main content

write_bytes_atomic

Function write_bytes_atomic 

Source
pub fn write_bytes_atomic(path: &Path, bytes: &[u8]) -> Result<(), String>
Expand description

Replace path with bytes atomically, leaving no temp file behind on any exit path, and reap temps abandoned by processes that are gone.

The caller is expected to already hold whatever lock serializes writers of path (both shard caches take an flock first); this function only guarantees that a reader never sees a half-written file and that a failed write does not leak one.