Smart config loading, initializing, normal and template works, do some last tests on Linux

This commit is contained in:
Anynomouss
2025-04-10 17:16:45 +02:00
parent 39f00fe8b7
commit a37aa09f9f
3 changed files with 11 additions and 27 deletions
+9 -17
View File
@@ -188,9 +188,12 @@ pub fn initial_setup_wallet(
create_path: bool,
) -> Result<GlobalWalletConfig, ConfigError> {
if create_path {
if let Some(path_fixed) = &data_path {
if let Some(p) = data_path.clone() {
// Fix for a bug in the rust fs package to handle "\" in paths
fs::create_dir_all(&path_fixed)?;
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)?;
}
}
@@ -349,26 +352,15 @@ impl GlobalWalletConfig {
/// Update paths
pub fn update_paths(&mut self, wallet_home: &PathBuf, node_home: &PathBuf) {
// 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 data_file_dir = wallet_home.clone();
let mut node_secret_path = node_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
let mut secret_path = wallet_home.clone();
let mut log_path = wallet_home.clone();
let tor_path = wallet_home.clone();
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 =
+1 -9
View File
@@ -166,16 +166,8 @@ impl WalletSeed {
// create directory if it doesn't exist
fs::create_dir_all(data_file_dir).map_err(|_| Error::IO)?;
// 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,);
let seed_file_path = &format!("{}{}{}", data_file_dir, 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 {
+1 -1
View File
@@ -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 path since backslashes in paths do not work on Linux
let d = d.to_owned().replace("/", "\\"); // Fix for fs to work with paths on Linux
current_dir = Some(PathBuf::from(d));
}
None => {