logo

Function nannou::io::safe_file_save[][src]

pub fn safe_file_save<P>(path: P, content: &[u8]) -> Result<()> where
    P: AsRef<Path>, 
Expand description

Safely save a file with the given contents, replacing the original if necessary.

Works as follows:

  1. Writes the content to a .tmp file.
  2. Renames the original file (if there is one) to .backup.
  3. Renames the .tmp file to the desired path file name.
  4. Removes the .backup file.

This should at least ensure that a .backup of the original file exists if something goes wrong while writing the new one.

This function also creates all necessary parent directories if they do not exist.