Merge #85: Delete install target datadir in case of failure

e9fa816be7c6ddbf64413dc4df6940d0f90c1f87 Delete install target datadir in case of failure (edouard)

Pull request description:

  close #20

ACKs for top commit:
  edouardparis:
    Self-ACK e9fa816be7c6ddbf64413dc4df6940d0f90c1f87

Tree-SHA512: 21b78bdad3a3e5127703211e5d119dc9ec88e4bc881ab744e1f6e20d51000af8b5aac4a12f19c775576c69ce958cac7d905378ec8fa4d69e4398fb5fedb61a05
This commit is contained in:
edouard 2022-11-10 17:03:58 +01:00
commit 5595e91e57
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F

View File

@ -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()