diff --git a/gui/Cargo.lock b/gui/Cargo.lock index 1256ebf04..0b91ef6f1 100644 --- a/gui/Cargo.lock +++ b/gui/Cargo.lock @@ -1640,7 +1640,7 @@ dependencies = [ [[package]] name = "liana" version = "0.2.0" -source = "git+https://github.com/wizardsardine/liana?branch=master#66e37a2cdf489308d2aeb6a8bf509fd71f68c5ef" +source = "git+https://github.com/wizardsardine/liana?branch=master#88e5977166373437169ea00e54f365085afd03c0" dependencies = [ "backtrace", "base64", diff --git a/gui/src/installer/mod.rs b/gui/src/installer/mod.rs index dc87d294c..316f88448 100644 --- a/gui/src/installer/mod.rs +++ b/gui/src/installer/mod.rs @@ -138,7 +138,19 @@ impl Installer { 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"); + log::warn!("Installation failed. Cleaning up the leftover data directory."); + if let Err(e) = std::fs::remove_dir_all(&data_dir) { + log::error!( + "Failed to completely delete the data directory (path: '{}'): {}", + data_dir.to_string_lossy(), + e + ); + } else { + log::warn!( + "Successfully deleted data directory at '{}'.", + data_dir.to_string_lossy() + ); + }; self.steps .get_mut(self.current) .expect("There is always a step") @@ -161,13 +173,25 @@ impl Installer { } } +pub fn daemon_check(cfg: liana::config::Config) -> Result<(), Error> { + // Start Daemon to check correctness of installation + match liana::DaemonHandle::start_default(cfg) { + Ok(daemon) => { + daemon.shutdown(); + Ok(()) + } + Err(e) => Err(Error::Unexpected(format!( + "Failed to start Liana daemon: {}", + e + ))), + } +} + pub async fn install(ctx: Context) -> Result { + log::info!("installing"); let mut cfg: liana::config::Config = ctx.extract_daemon_config(); - // Start Daemon to check correctness of installation - let daemon = liana::DaemonHandle::start_default(cfg.clone()).map_err(|e| { - Error::Unexpected(format!("Failed to start daemon with entered config: {}", e)) - })?; - daemon.shutdown(); + daemon_check(cfg.clone())?; + log::info!("daemon checked"); cfg.data_dir = Some(cfg.data_dir.unwrap().canonicalize().map_err(|e| { @@ -178,8 +202,8 @@ pub async fn install(ctx: Context) -> Result { datadir_path.push(cfg.bitcoin_config.network.to_string()); // Step needed because of ValueAfterTable error in the toml serialize implementation. - let daemon_config = - toml::Value::try_from(&cfg).expect("daemon::Config has a proper Serialize implementation"); + let daemon_config = toml::Value::try_from(&cfg) + .map_err(|e| Error::Unexpected(format!("Failed to serialize daemon config: {}", e)))?; // create lianad configuration file let daemon_config_path = create_and_write_file( @@ -188,6 +212,8 @@ pub async fn install(ctx: Context) -> Result { daemon_config.to_string().as_bytes(), )?; + log::info!("Daemon config file created"); + // create liana GUI configuration file let gui_config_path = create_and_write_file( datadir_path.clone(), @@ -197,18 +223,24 @@ pub async fn install(ctx: Context) -> Result { Error::Unexpected(format!("Failed to canonicalize daemon config path: {}", e)) })?, )) - .unwrap() + .map_err(|e| Error::Unexpected(format!("Failed to serialize gui config: {}", e)))? .as_bytes(), )?; + log::info!("Gui config file created"); + // create liana GUI settings file let settings: gui_settings::Settings = ctx.extract_gui_settings(); create_and_write_file( datadir_path, gui_settings::DEFAULT_FILE_NAME, - serde_json::to_string_pretty(&settings).unwrap().as_bytes(), + serde_json::to_string_pretty(&settings) + .map_err(|e| Error::Unexpected(format!("Failed to serialize settings: {}", e)))? + .as_bytes(), )?; + log::info!("Settings file created"); + Ok(gui_config_path) }