gui: truncate config file before writing

This is required in case the updated config file has a shorter
length than the existing file.
This commit is contained in:
jp1ac4 2023-12-21 17:26:36 +00:00
parent 386b4cb3dd
commit a4b982d972
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B

View File

@ -202,22 +202,19 @@ impl App {
let daemon = EmbeddedDaemon::start(cfg)?;
self.daemon = Arc::new(daemon);
let mut daemon_config_file = OpenOptions::new()
.write(true)
.open(daemon_config_path)
.map_err(|e| Error::Config(e.to_string()))?;
let content =
toml::to_string(&self.daemon.config()).map_err(|e| Error::Config(e.to_string()))?;
daemon_config_file
OpenOptions::new()
.write(true)
.truncate(true)
.open(daemon_config_path)
.map_err(|e| Error::Config(e.to_string()))?
.write_all(content.as_bytes())
.map_err(|e| {
warn!("failed to write to file: {:?}", e);
Error::Config(e.to_string())
})?;
Ok(())
})
}
pub fn load_wallet(&mut self) -> Result<Arc<Wallet>, Error> {