Following up from keepass-rs#355.
To prevent another issue like the one discussed above causing potential loss of data, consider the following approach.
Instead of directly saving databases to the desired path:
db.save(
&mut std::fs::File::create(&*path)?,
DatabaseKey::new().with_password(password.expose_secret()),
)?;
First write into a buffer and then only overwrite the destination path if database serialization was successful:
let mut buf: Vec<u8> = Vec::new();
db.save(
&mut buf,
DatabaseKey::new().with_password(password.expose_secret()),
)?;
let mut f = std::fs::File::create(&*path)?;
f.write_all(&buf)?;
Following up from keepass-rs#355.
To prevent another issue like the one discussed above causing potential loss of data, consider the following approach.
Instead of directly saving databases to the desired path:
First write into a buffer and then only overwrite the destination path if database serialization was successful: