From e9fa816be7c6ddbf64413dc4df6940d0f90c1f87 Mon Sep 17 00:00:00 2001 From: edouard Date: Thu, 10 Nov 2022 12:11:33 +0100 Subject: [PATCH] Delete install target datadir in case of failure close #20 --- gui/src/installer/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gui/src/installer/mod.rs b/gui/src/installer/mod.rs index 4b425bcc..ac11eb3c 100644 --- a/gui/src/installer/mod.rs +++ b/gui/src/installer/mod.rs @@ -114,6 +114,18 @@ impl Installer { .update(message); Command::perform(install(self.context.clone()), Message::Installed) } + Message::Installed(Err(e)) => { + let mut data_dir = self.context.data_dir.clone().unwrap(); + data_dir.push(self.context.bitcoin_config.network.to_string()); + // In case of failure during install, block the thread to + // deleted the data_dir/network directory in order to start clean again. + std::fs::remove_dir_all(data_dir).expect("Correctly deleted"); + self.steps + .get_mut(self.current) + .expect("There is always a step") + .update(Message::Installed(Err(e))); + Command::none() + } Message::Event(Event::Window(window::Event::CloseRequested)) => { self.stop(); Command::none()