Function nannou::io::safe_file_save
source · pub fn safe_file_save<P>(path: P, content: &[u8]) -> Result<()>
Expand description
Safely save a file with the given contents, replacing the original if necessary.
Works as follows:
- Writes the content to a
.tmp
file. - Renames the original file (if there is one) to
.backup
. - Renames the
.tmp
file to the desired path file name. - 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.