atomic_cp

Function atomic_cp 

Source
pub fn atomic_cp(from: &Path, to: &Path) -> Result<()>
Expand description

Atomically copies a file from from to to.

The content is first written to a uniquely named temporary sibling (with PID and timestamp) and then moved into place with std::fs::rename. This minimizes the window where readers could observe a partially written file.

§Errors

  • A filesystem operation (open/read/write/remove) fails.
  • from Does not exist.
  • The atomic rename fails.
  • The destination’s parent directory or file name cannot be resolved.
  • The temporary copy fails.