Skip to main content

atomic_write

Function atomic_write 

Source
pub fn atomic_write(path: &Path, content: &str) -> SyncResult<()>
Expand description

Write content to a file atomically.

This function:

  1. Writes content to a temporary file (same path with .tmp extension)
  2. Calls fsync to ensure data is on disk
  3. Atomically renames the temp file to the target path

If any step fails, the original file (if any) remains untouched.

ยงErrors

Returns an error if any file operation fails.