diff --git a/config/src/config.rs b/config/src/config.rs index ef6f75a..f661e68 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -188,12 +188,9 @@ pub fn initial_setup_wallet( create_path: bool, ) -> Result { if create_path { - if let Some(p) = data_path.clone() { + if let Some(path_fixed) = &data_path { // Fix for a bug in the rust fs package to handle "\" in paths - let p_fix = p.clone(); - let p_fix = p_fix.to_str().unwrap().to_owned().replace("\\", "/"); - let p_fix = PathBuf::from(p_fix); - fs::create_dir_all(p_fix)?; + fs::create_dir_all(&path_fixed)?; } } @@ -352,15 +349,26 @@ impl GlobalWalletConfig { /// Update paths pub fn update_paths(&mut self, wallet_home: &PathBuf, node_home: &PathBuf) { - let mut data_file_dir = wallet_home.clone(); + // Below code formats the path to use "\\" in line with all paths in the toml file + let wallet_home_formatted = wallet_home.clone().clone(); + let wallet_home_formatted = wallet_home_formatted + .to_str() + .unwrap() + .to_owned() + .replace("/", "\\"); + let wallet_home_formatted = PathBuf::from(wallet_home_formatted); + // Clone paths for editing + let mut data_file_dir = wallet_home_formatted.clone(); let mut node_secret_path = node_home.clone(); - let mut secret_path = wallet_home.clone(); - let mut log_path = wallet_home.clone(); - let tor_path = wallet_home.clone(); + let mut secret_path = wallet_home_formatted.clone(); + let mut log_path = wallet_home_formatted.clone(); + let tor_path = wallet_home_formatted.clone(); + // Push the respective directories to get the final paths node_secret_path.push(API_SECRET_FILE_NAME); data_file_dir.push(GRIN_WALLET_DIR); secret_path.push(OWNER_API_SECRET_FILE_NAME); log_path.push(WALLET_LOG_FILE_NAME); + // Update the config variabless with the update paths self.members.as_mut().unwrap().wallet.data_file_dir = data_file_dir.to_str().unwrap().to_owned(); self.members.as_mut().unwrap().wallet.node_api_secret_path = diff --git a/impls/src/lifecycle/seed.rs b/impls/src/lifecycle/seed.rs index e7b6b46..5c6681f 100644 --- a/impls/src/lifecycle/seed.rs +++ b/impls/src/lifecycle/seed.rs @@ -166,8 +166,16 @@ impl WalletSeed { // create directory if it doesn't exist fs::create_dir_all(data_file_dir).map_err(|_| Error::IO)?; - let seed_file_path = &format!("{}{}{}", data_file_dir, MAIN_SEPARATOR, SEED_FILE,); + // Format data path properly + let data_file_dir_formatted = data_file_dir; + let data_file_dir_formatted = + data_file_dir_formatted.replace("/", &MAIN_SEPARATOR.to_string()); + let data_file_dir_formatted = + data_file_dir_formatted.replace("\\", &MAIN_SEPARATOR.to_string()); + let seed_file_path = + &format!("{}{}{}", data_file_dir_formatted, MAIN_SEPARATOR, SEED_FILE,); + // Inform the user the seed has been generated warn!("Generating wallet seed file at: {}", seed_file_path); let exists = WalletSeed::seed_file_exists(data_file_dir)?; if exists && !test_mode { diff --git a/src/bin/grin-wallet.rs b/src/bin/grin-wallet.rs index 36d0385..0df68e5 100644 --- a/src/bin/grin-wallet.rs +++ b/src/bin/grin-wallet.rs @@ -86,7 +86,7 @@ fn real_main() -> i32 { let res = args.value_of("top_level_dir"); match res { Some(d) => { - let d = d.to_owned().replace("/", "\\"); // Fix for fs to work with paths on Linux + let d = d.to_owned().replace("\\", "/"); // Fix for path since backslashes in paths do not work on Linux current_dir = Some(PathBuf::from(d)); } None => {