fn flush()

in merkledb/src/merklememdb.rs [379:402]


    fn flush(&mut self) -> Result<()> {
        if self.changed && !self.path.as_os_str().is_empty() {
            use std::io::{Error, ErrorKind};
            let dbpath = self.path.parent().ok_or_else(|| {
                Error::new(
                    ErrorKind::InvalidInput,
                    format!("Unable to find MerkleDB output parent path from {:?}", self.path),
                )
            })?;
            // we prefix with "[PID]." for now. We should be able to do a cleanup
            // in the future.
            let tempfile = tempfile::Builder::new()
                .prefix(&format!("{}.", std::process::id()))
                .suffix(".db")
                .tempfile_in(dbpath)?;
            debug!("Flushing DB to {:?} via {:?}", self.path, tempfile.path());
            let f = BufWriter::new(&tempfile);
            self.write_into(f);
            self.changed = false;
            // e is a PersistError. e.error is an IoError
            tempfile.persist(&self.path).map_err(|e| e.error)?;
        }
        Ok(())
    }