From a4b982d972b9a5d823b48ae1f1b979481e6785b6 Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:26:36 +0000 Subject: [PATCH] gui: truncate config file before writing This is required in case the updated config file has a shorter length than the existing file. --- gui/src/app/mod.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs index d217bc64..0f3443c3 100644 --- a/gui/src/app/mod.rs +++ b/gui/src/app/mod.rs @@ -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, Error> {