Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Correct file paths #2966

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ report
*.mdb
/data/
*.sqlite3
base_layer/wallet_ffi/build.config
/base_layer/wallet_ffi/build.config
/base_layer/wallet_ffi/logs/
base_layer/wallet_ffi/.cargo/config
/config
/stibbons
/wallet
/base_layer/wallet_ffi/.cargo/config
keys.json
node_modules
/integration_tests/temp
Expand Down
69 changes: 67 additions & 2 deletions applications/tari_app_utilities/src/initialization.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utilities::ExitCodes;
use config::Config;
use structopt::StructOpt;
use tari_common::{configuration::bootstrap::ApplicationType, ConfigBootstrap, GlobalConfig};
use tari_common::{configuration::bootstrap::ApplicationType, ConfigBootstrap, DatabaseType, GlobalConfig};

pub const LOG_TARGET: &str = "tari::application";

Expand All @@ -21,7 +21,72 @@ pub fn init_configuration(
bootstrap.initialize_logging()?;

// Populate the configuration struct
let global_config =
let mut global_config =
GlobalConfig::convert_from(cfg.clone()).map_err(|err| ExitCodes::ConfigError(err.to_string()))?;
check_file_paths(&mut global_config, &bootstrap);
Ok((bootstrap, global_config, cfg))
}

fn check_file_paths(config: &mut GlobalConfig, bootstrap: &ConfigBootstrap) {
let prepend = bootstrap.base_path.clone();
if !config.data_dir.is_absolute() {
let mut path = prepend.clone();
path.push(config.data_dir.clone());
config.data_dir = path;
if let DatabaseType::LMDB(_) = config.db_type {
config.db_type = DatabaseType::LMDB(config.data_dir.join("db"));
}
}
if !config.peer_db_path.is_absolute() {
let mut path = prepend.clone();
path.push(config.peer_db_path.clone());
config.peer_db_path = path;
}
if !config.base_node_identity_file.is_absolute() {
let mut path = prepend.clone();
path.push(config.base_node_identity_file.clone());
config.base_node_identity_file = path;
}
if !config.base_node_tor_identity_file.is_absolute() {
let mut path = prepend.clone();
path.push(config.base_node_tor_identity_file.clone());
config.base_node_tor_identity_file = path;
}
if !config.console_wallet_db_file.is_absolute() {
let mut path = prepend.clone();
path.push(config.console_wallet_db_file.clone());
config.console_wallet_db_file = path;
}
if !config.console_wallet_peer_db_path.is_absolute() {
let mut path = prepend.clone();
path.push(config.console_wallet_peer_db_path.clone());
config.console_wallet_peer_db_path = path;
}
if !config.console_wallet_identity_file.is_absolute() {
let mut path = prepend.clone();
path.push(config.console_wallet_identity_file.clone());
config.console_wallet_identity_file = path;
}
if !config.console_wallet_tor_identity_file.is_absolute() {
let mut path = prepend.clone();
path.push(config.console_wallet_tor_identity_file.clone());
config.console_wallet_tor_identity_file = path;
}
if !config.wallet_db_file.is_absolute() {
let mut path = prepend.clone();
path.push(config.wallet_db_file.clone());
config.wallet_db_file = path;
}
if !config.wallet_peer_db_path.is_absolute() {
let mut path = prepend.clone();
path.push(config.wallet_db_file.clone());
config.wallet_db_file = path;
}
if let Some(file_path) = config.console_wallet_notify_file.clone() {
if file_path.is_absolute() {
let mut path = prepend;
path.push(file_path);
config.console_wallet_notify_file = Some(path);
}
}
}
4 changes: 2 additions & 2 deletions applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ pub const LOG_TARGET: &str = "base_node::app";
/// Application entry point
fn main() {
if let Err(exit_code) = main_inner() {
eprintln!("{}", exit_code);
eprintln!("{:?}", exit_code);
error!(
target: LOG_TARGET,
"Exiting with code ({}): {}",
"Exiting with code ({}): {:?}",
exit_code.as_i32(),
exit_code
);
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_console_wallet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn main() {
match main_inner() {
Ok(_) => process::exit(0),
Err(exit_code) => {
eprintln!("{}", exit_code);
eprintln!("{:?}", exit_code);
error!(
target: LOG_TARGET,
"Exiting with code ({}): {}",
"Exiting with code ({}): {:?}",
exit_code.as_i32(),
exit_code
);
Expand Down
8 changes: 4 additions & 4 deletions common/config/presets/tari_config_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ grpc_base_node_address = "127.0.0.1:18142"
grpc_console_wallet_address = "127.0.0.1:18143"

# A path to the file that stores your node identity and secret key
base_node_identity_file = "./config/base_node_id.json"
base_node_identity_file = "config/base_node_id.json"

# A path to the file that stores your console wallet's node identity and secret key
console_wallet_identity_file = "./config/console_wallet_id.json"
console_wallet_identity_file = "config/console_wallet_id.json"

# -------------- Transport configuration --------------
# Use TCP to connect to the Tari network. This transport can only communicate with TCP/IP addresses, so peers with
Expand Down Expand Up @@ -304,10 +304,10 @@ tor_control_auth = "none" # or "password=xxxxxx"
#socks5_auth = "none" # or "username_password=username:xxxxxxx"

# A path to the file that stores the tor hidden service private key, if using the tor transport.
base_node_tor_identity_file = "./config/base_node_tor.json"
base_node_tor_identity_file = "config/base_node_tor.json"

# A path to the file that stores the console wallet's tor hidden service private key, if using the tor transport.
console_wallet_tor_identity_file = "./config/cosole_wallet_tor.json"
console_wallet_tor_identity_file = "config/cosole_wallet_tor.json"

########################################################################################################################
# #
Expand Down
9 changes: 6 additions & 3 deletions common/src/dir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ pub fn default_subdir(path: &str, base_dir: Option<&PathBuf>) -> String {

pub fn default_path(filename: &str, base_path: Option<&PathBuf>) -> PathBuf {
let mut home = base_path.cloned().unwrap_or_else(|| {
let mut home = dirs_next::home_dir().unwrap_or_else(|| PathBuf::from("."));
home.push(".tari");
home
[
dirs_next::home_dir().unwrap_or_else(|| PathBuf::from(".")),
PathBuf::from(".tari"),
]
.iter()
.collect()
});
home.push(filename);
home
Expand Down