// Does NOT sync the directory. A sync of the directory still needs to be
// done to ensure the atomic rename is persisted.
Does NOT sync the directory. A sync of the directory still needs to be
done to ensure the atomic rename is persisted.
Does NOT sync the directory . A sync of the directory still needs to be done to ensure the atomic rename is persisted .
pub fn atomic_add_file(p: &Path, contents: &[u8]) -> Result<(), std::io::Error> {
    let random_suffix = {
        let mut buf = [0; 8];
        crypto::randombytes(&mut buf[..]);
        hex::easy_encode_to_string(&buf[..])
    };
    let temp_path = p
        .to_string_lossy()
        .chars()
        .chain(random_suffix.chars())
        .chain(".tmp".chars())
        .collect::<String>();
    let mut tmp_file = std::fs::OpenOptions::new()
        .write(true)
        .create_new(true)
        .open(&temp_path)?;
    tmp_file.write_all(contents)?;
    tmp_file.sync_all()?;
    std::fs::rename(temp_path, p)?;
    Ok(())
}
pub fn atomic_add_file ( p : & Path , contents : & [ u8 ] ) -> Result < ( ) , std :: io :: Error > { let random_suffix = { let mut buf = [ 0 ; 8 ] ; crypto :: randombytes ( & mut buf [ .. ] ) ; hex :: easy_encode_to_string ( & buf [ .. ] ) } ; let temp_path = p . to_string_lossy ( ) . chars ( ) . chain ( random_suffix . chars ( ) ) . chain ( " " . chars ( ) ) . collect :: < String > ( ) ; let mut tmp_file = std :: fs :: OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( & temp_path ) ? ; tmp_file . write_all ( contents ) ? ; tmp_file . sync_all ( ) ? ; std :: fs :: rename ( temp_path , p ) ? ; Ok ( ( ) ) }
Does NOT sync the directory.
Does NOT sync the directory .
p
&Path
contents
&[u8]