Merge #894: gui: truncate config file before writing

a4b982d972b9a5d823b48ae1f1b979481e6785b6 gui: truncate config file before writing (jp1ac4)

Pull request description:

  This is required in case the updated config file has a shorter length than the existing file.

  For example, if changing cookie path from absolute path to relative path, the updated config file will have invalid content without this change.

ACKs for top commit:
  darosior:
    Makes sense but i'm missing context surrounding this code. Github utACK a4b982d972b9a5d823b48ae1f1b979481e6785b6. Will let Edouard confirm it's OK.

Tree-SHA512: 0fb89e190ba934661ceeec2401390faa9b3cad6858d0a3a9fdd48bb6b7a20bcd57277422ee6b8b09a59c67f0750072481755341f7b9e9f618154b04e62cb4bf2
This commit is contained in:
Antoine Poinsot 2023-12-28 16:46:20 +01:00
commit b8f8d1b944
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

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> {