replace_home for password_files, reserved_peers and log_file (#8324)

* replace_home for password_files, reserved_peers and log_file

* typo: arg_log_file is Option
This commit is contained in:
Wei Tang 2018-04-09 22:34:47 +08:00 committed by Marek Kotewicz
parent d97cf34138
commit 431b27d3e1

View File

@ -149,7 +149,7 @@ impl Configuration {
if self.args.cmd_signer_new_token { if self.args.cmd_signer_new_token {
Cmd::SignerToken(ws_conf, ui_conf, logger_config.clone()) Cmd::SignerToken(ws_conf, ui_conf, logger_config.clone())
} else if self.args.cmd_signer_sign { } else if self.args.cmd_signer_sign {
let pwfile = self.args.arg_password.first().map(|pwfile| { let pwfile = self.accounts_config()?.password_files.first().map(|pwfile| {
PathBuf::from(pwfile) PathBuf::from(pwfile)
}); });
Cmd::SignerSign { Cmd::SignerSign {
@ -186,7 +186,7 @@ impl Configuration {
iterations: self.args.arg_keys_iterations, iterations: self.args.arg_keys_iterations,
path: dirs.keys, path: dirs.keys,
spec: spec, spec: spec,
password_file: self.args.arg_password.first().map(|x| x.to_owned()), password_file: self.accounts_config()?.password_files.first().map(|x| x.to_owned()),
}; };
AccountCmd::New(new_acc) AccountCmd::New(new_acc)
} else if self.args.cmd_account_list { } else if self.args.cmd_account_list {
@ -220,8 +220,8 @@ impl Configuration {
iterations: self.args.arg_keys_iterations, iterations: self.args.arg_keys_iterations,
path: dirs.keys, path: dirs.keys,
spec: spec, spec: spec,
wallet_path: self.args.arg_wallet_import_path.unwrap().clone(), wallet_path: self.args.arg_wallet_import_path.clone().unwrap(),
password_file: self.args.arg_password.first().map(|x| x.to_owned()), password_file: self.accounts_config()?.password_files.first().map(|x| x.to_owned()),
}; };
Cmd::ImportPresaleWallet(presale_cmd) Cmd::ImportPresaleWallet(presale_cmd)
} else if self.args.cmd_import { } else if self.args.cmd_import {
@ -456,7 +456,7 @@ impl Configuration {
LogConfig { LogConfig {
mode: self.args.arg_logging.clone(), mode: self.args.arg_logging.clone(),
color: !self.args.flag_no_color && !cfg!(windows), color: !self.args.flag_no_color && !cfg!(windows),
file: self.args.arg_log_file.clone(), file: self.args.arg_log_file.as_ref().map(|log_file| replace_home(&self.directories().base, log_file)),
} }
} }
@ -508,7 +508,7 @@ impl Configuration {
iterations: self.args.arg_keys_iterations, iterations: self.args.arg_keys_iterations,
refresh_time: self.args.arg_accounts_refresh, refresh_time: self.args.arg_accounts_refresh,
testnet: self.args.flag_testnet, testnet: self.args.flag_testnet,
password_files: self.args.arg_password.clone(), password_files: self.args.arg_password.iter().map(|s| replace_home(&self.directories().base, s)).collect(),
unlocked_accounts: to_addresses(&self.args.arg_unlock)?, unlocked_accounts: to_addresses(&self.args.arg_unlock)?,
enable_hardware_wallets: !self.args.flag_no_hardware_wallets, enable_hardware_wallets: !self.args.flag_no_hardware_wallets,
enable_fast_unlock: self.args.flag_fast_unlock, enable_fast_unlock: self.args.flag_fast_unlock,
@ -728,8 +728,10 @@ impl Configuration {
match self.args.arg_reserved_peers { match self.args.arg_reserved_peers {
Some(ref path) => { Some(ref path) => {
let path = replace_home(&self.directories().base, path);
let mut buffer = String::new(); let mut buffer = String::new();
let mut node_file = File::open(path).map_err(|e| format!("Error opening reserved nodes file: {}", e))?; let mut node_file = File::open(&path).map_err(|e| format!("Error opening reserved nodes file: {}", e))?;
node_file.read_to_string(&mut buffer).map_err(|_| "Error reading reserved node file")?; node_file.read_to_string(&mut buffer).map_err(|_| "Error reading reserved node file")?;
let lines = buffer.lines().map(|s| s.trim().to_owned()).filter(|s| !s.is_empty() && !s.starts_with("#")).collect::<Vec<_>>(); let lines = buffer.lines().map(|s| s.trim().to_owned()).filter(|s| !s.is_empty() && !s.starts_with("#")).collect::<Vec<_>>();