Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fixed --base-path on windows #4193

Merged
merged 2 commits into from
Jan 18, 2017
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
11 changes: 7 additions & 4 deletions parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ usage! {
flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(),
flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(),
flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
flag_base_path: String = dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(),
flag_db_path: String = dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone(),
flag_keys_path: String = "$BASE/keys", or |c: &Config| otry!(c.parity).keys_path.clone(),
flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),

Expand Down Expand Up @@ -289,6 +287,11 @@ usage! {
flag_no_color: bool = false,
or |c: &Config| otry!(c.misc).color.map(|c| !c).clone(),
}
{
// Values with optional default value.
flag_base_path: Option<String>, display dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone().map(Some),
flag_db_path: Option<String>, display dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone().map(Some),
}
}


Expand Down Expand Up @@ -547,8 +550,8 @@ mod tests {
flag_no_download: false,
flag_no_consensus: false,
flag_chain: "xyz".into(),
flag_base_path: "$HOME/.parity".into(),
flag_db_path: "$HOME/.parity/chains".into(),
flag_base_path: Some("$HOME/.parity".into()),
flag_db_path: Some("$HOME/.parity/chains".into()),
flag_keys_path: "$HOME/.parity/keys".into(),
flag_identity: "".into(),

Expand Down
22 changes: 22 additions & 0 deletions parity/cli/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ macro_rules! usage {
$field:ident : $typ:ty = $default:expr, or $from_config:expr,
)*
}
{
$(
$field_s:ident : $typ_s:ty, display $default_s:expr, or $from_config_s:expr,
)*
}
) => {
use toml;
use std::{fs, io, process};
Expand Down Expand Up @@ -108,6 +113,10 @@ macro_rules! usage {
$(
pub $field: $typ,
)*

$(
pub $field_s: $typ_s,
)*
}

impl Default for Args {
Expand All @@ -120,6 +129,10 @@ macro_rules! usage {
$(
$field: $default.into(),
)*

$(
$field_s: Default::default(),
)*
}
}
}
Expand All @@ -132,6 +145,9 @@ macro_rules! usage {
$(
$field: Option<$typ>,
)*
$(
$field_s: Option<$typ_s>,
)*
}

impl Args {
Expand Down Expand Up @@ -206,6 +222,9 @@ macro_rules! usage {
$(
args.$field = self.$field.or_else(|| $from_config(&config)).unwrap_or_else(|| $default.into());
)*
$(
args.$field_s = self.$field_s.or_else(|| $from_config_s(&config)).unwrap_or(None);
)*
args
}

Expand All @@ -222,6 +241,9 @@ macro_rules! usage {
// "named argument never used" error
// $field = $default,
)*
$(
$field_s = $default_s,
)*
)
}
}
Expand Down
15 changes: 9 additions & 6 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_pri
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use ethcore_logger::Config as LogConfig;
use dir::{Directories, default_hypervisor_path, default_local_path};
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
use dapps::Configuration as DappsConfiguration;
use signer::{Configuration as SignerConfiguration};
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
Expand Down Expand Up @@ -734,13 +734,16 @@ impl Configuration {
use util::path;

let local_path = default_local_path();
let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_base_path));

let db_path = if self.args.flag_datadir.is_some() {
replace_home(&data_path, &self.args.flag_db_path)
let base_path = self.args.flag_base_path.as_ref().map_or_else(|| default_data_path(), |s| s.clone());
let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&base_path));
let base_db_path = if self.args.flag_base_path.is_some() && self.args.flag_db_path.is_none() {
// If base_path is set and db_path is not we default to base path subdir instead of LOCAL.
"$BASE/chains"
} else {
replace_home_for_db(&data_path, &local_path, &self.args.flag_db_path)
self.args.flag_db_path.as_ref().map_or(dir::CHAINS_PATH, |s| &s)
};

let db_path = replace_home_for_db(&data_path, &local_path, &base_db_path);
let keys_path = replace_home(&data_path, &self.args.flag_keys_path);
let dapps_path = replace_home(&data_path, &self.args.flag_dapps_path);
let ui_path = replace_home(&data_path, &self.args.flag_ui_path);
Expand Down