pub fn atomic_replace_file<P: AsRef<Path>>(
original_path: P,
temp_path: P,
) -> Result<(), Vec<Diagnostic>>Expand description
Atomically replace a file using rsync-style temp files
This performs the following sequence:
- Write new content to temp_path (caller’s responsibility - already done)
- Move original_path -> .original_path.{random}.old (backup)
- Move temp_path -> original_path (replace)
- Delete .original_path.{random}.old (cleanup)
If any step fails, attempts to recover by restoring the backup.
§Arguments
original_path- The file to be replacedtemp_path- The temporary file containing the new content
§Errors
Returns diagnostics if any step of the operation fails. The function attempts automatic recovery by restoring the backup if the replacement fails.