Skip to main content

write_json_atomic

Function write_json_atomic 

Source
pub fn write_json_atomic<T, P>(path: P, value: &T) -> Result<()>
where T: Serialize, P: AsRef<Path>,
Expand description

Serializes value as compact JSON and writes it to path atomically.

Writes to a temporary file in the same directory, fsyncs it, then renames it over path, so a concurrent reader never observes a partially written file. Used by the quota-cache writers (the background quota workers each persist their last-known-good snapshot).

ยงErrors

Returns an error if the parent directory cannot be created, the temp file cannot be written, or the final rename fails.