Skip to main content

Module persist

Module persist 

Source
Expand description

Common persistence helpers: atomic JSON file writes with tmp + rename. Sensitive files can opt-in to 0600 permissions on Unix.

Functionsยง

atomic_write_json
Atomically write a serializable value to path using tmp + rename. Creates parent directories if needed.
atomic_write_json_with_perms
Atomically write a serializable value to path using tmp + rename. If restrict_perms is true, sets file permissions to 0o600 on Unix.
read_json
Read and deserialize JSON from path. Returns Ok(None) if the file does not exist.
remove_file_if_exists
Remove a file if it exists. No error if not found.
tmp_path_for
Helper: build a tmp path for a given file path.