Using local path on Windows (#4017)

* Using non-roaming path on Windows

* Fixing test
This commit is contained in:
Tomasz Drwięga 2017-01-05 14:12:54 +01:00 committed by Gav Wood
parent 91f864b2b7
commit a076ffaf8c
5 changed files with 36 additions and 13 deletions

View File

@ -16,7 +16,7 @@
#[macro_use] #[macro_use]
mod usage; mod usage;
use dir::default_data_path; use dir;
usage! { usage! {
{ {
@ -90,8 +90,8 @@ usage! {
flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(), 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_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_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
flag_base_path: String = default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(), flag_base_path: String = dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(),
flag_db_path: String = "$BASE/chains", or |c: &Config| otry!(c.parity).db_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_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(), flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),

View File

@ -336,7 +336,7 @@ Legacy Options:
testnet --keys-path $HOME/parity/testnet-keys. testnet --keys-path $HOME/parity/testnet-keys.
Overrides the --keys-path option. Overrides the --keys-path option.
--import-geth-keys Attempt to import keys from Geth client. --import-geth-keys Attempt to import keys from Geth client.
--datadir PATH Equivalent to --db-path PATH. --datadir PATH Equivalent to --base-path PATH.
--networkid INDEX Equivalent to --network-id INDEX. --networkid INDEX Equivalent to --network-id INDEX.
--peers NUM Equivalent to --min-peers NUM. --peers NUM Equivalent to --min-peers NUM.
--nodekey KEY Equivalent to --node-key KEY. --nodekey KEY Equivalent to --node-key KEY.

View File

@ -30,11 +30,11 @@ use ethcore::verification::queue::VerifierSettings;
use rpc::{IpcConfiguration, HttpConfiguration}; use rpc::{IpcConfiguration, HttpConfiguration};
use ethcore_rpc::NetworkSettings; use ethcore_rpc::NetworkSettings;
use cache::CacheConfig; use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_for_db,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy}; 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 params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use ethcore_logger::Config as LogConfig; use ethcore_logger::Config as LogConfig;
use dir::{Directories, default_hypervisor_path}; use dir::{Directories, default_hypervisor_path, default_local_path};
use dapps::Configuration as DappsConfiguration; use dapps::Configuration as DappsConfiguration;
use signer::{Configuration as SignerConfiguration}; use signer::{Configuration as SignerConfiguration};
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack}; use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
@ -707,9 +707,14 @@ impl Configuration {
fn directories(&self) -> Directories { fn directories(&self) -> Directories {
use util::path; 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 data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_base_path));
let db_path = replace_home(&data_path, &self.args.flag_db_path); let db_path = if self.args.flag_datadir.is_some() {
replace_home(&data_path, &self.args.flag_db_path)
} else {
replace_home_for_db(&data_path, &local_path, &self.args.flag_db_path)
};
let keys_path = replace_home(&data_path, &self.args.flag_keys_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 dapps_path = replace_home(&data_path, &self.args.flag_dapps_path);
let ui_path = replace_home(&data_path, &self.args.flag_ui_path); let ui_path = replace_home(&data_path, &self.args.flag_ui_path);

View File

@ -18,7 +18,7 @@ use std::fs;
use std::path::{PathBuf, Path}; use std::path::{PathBuf, Path};
use util::{H64, H256}; use util::{H64, H256};
use util::journaldb::Algorithm; use util::journaldb::Algorithm;
use helpers::replace_home; use helpers::{replace_home, replace_home_for_db};
use app_dirs::{AppInfo, get_app_root, AppDataType}; use app_dirs::{AppInfo, get_app_root, AppDataType};
#[cfg(target_os = "macos")] const AUTHOR: &'static str = "Parity"; #[cfg(target_os = "macos")] const AUTHOR: &'static str = "Parity";
@ -31,6 +31,9 @@ use app_dirs::{AppInfo, get_app_root, AppDataType};
#[cfg(not(any(target_os = "windows", target_os = "macos")))] const PRODUCT: &'static str = "io.parity.ethereum"; #[cfg(not(any(target_os = "windows", target_os = "macos")))] const PRODUCT: &'static str = "io.parity.ethereum";
#[cfg(not(any(target_os = "windows", target_os = "macos")))] const PRODUCT_HYPERVISOR: &'static str = "io.parity.ethereum-updates"; #[cfg(not(any(target_os = "windows", target_os = "macos")))] const PRODUCT_HYPERVISOR: &'static str = "io.parity.ethereum-updates";
#[cfg(target_os = "windows")] pub const CHAINS_PATH: &'static str = "$LOCAL/chains";
#[cfg(not(target_os = "windows"))] pub const CHAINS_PATH: &'static str = "$BASE/chains";
// this const is irrelevent cause we do have migrations now, // this const is irrelevent cause we do have migrations now,
// but we still use it for backwards compatibility // but we still use it for backwards compatibility
const LEGACY_CLIENT_DB_VER_STR: &'static str = "5.3"; const LEGACY_CLIENT_DB_VER_STR: &'static str = "5.3";
@ -47,9 +50,10 @@ pub struct Directories {
impl Default for Directories { impl Default for Directories {
fn default() -> Self { fn default() -> Self {
let data_dir = default_data_path(); let data_dir = default_data_path();
let local_dir = default_local_path();
Directories { Directories {
base: replace_home(&data_dir, "$BASE"), base: replace_home(&data_dir, "$BASE"),
db: replace_home(&data_dir, "$BASE/chains"), db: replace_home_for_db(&data_dir, &local_dir, CHAINS_PATH),
keys: replace_home(&data_dir, "$BASE/keys"), keys: replace_home(&data_dir, "$BASE/keys"),
signer: replace_home(&data_dir, "$BASE/signer"), signer: replace_home(&data_dir, "$BASE/signer"),
dapps: replace_home(&data_dir, "$BASE/dapps"), dapps: replace_home(&data_dir, "$BASE/dapps"),
@ -209,6 +213,11 @@ pub fn default_data_path() -> String {
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned()) get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
} }
pub fn default_local_path() -> String {
let app_info = AppInfo { name: PRODUCT, author: AUTHOR };
get_app_root(AppDataType::UserCache, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
}
pub fn default_hypervisor_path() -> String { pub fn default_hypervisor_path() -> String {
let app_info = AppInfo { name: PRODUCT_HYPERVISOR, author: AUTHOR }; let app_info = AppInfo { name: PRODUCT_HYPERVISOR, author: AUTHOR };
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity-hypervisor".to_owned()) get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity-hypervisor".to_owned())
@ -217,14 +226,18 @@ pub fn default_hypervisor_path() -> String {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::Directories; use super::Directories;
use helpers::replace_home; use helpers::{replace_home, replace_home_for_db};
#[test] #[test]
fn test_default_directories() { fn test_default_directories() {
let data_dir = super::default_data_path(); let data_dir = super::default_data_path();
let local_dir = super::default_local_path();
let expected = Directories { let expected = Directories {
base: replace_home(&data_dir, "$BASE"), base: replace_home(&data_dir, "$BASE"),
db: replace_home(&data_dir, "$BASE/chains"), db: replace_home_for_db(&data_dir, &local_dir,
if cfg!(target_os = "windows") { "$LOCAL/chains" }
else { "$BASE/chains" }
),
keys: replace_home(&data_dir, "$BASE/keys"), keys: replace_home(&data_dir, "$BASE/keys"),
signer: replace_home(&data_dir, "$BASE/signer"), signer: replace_home(&data_dir, "$BASE/signer"),
dapps: replace_home(&data_dir, "$BASE/dapps"), dapps: replace_home(&data_dir, "$BASE/dapps"),

View File

@ -135,8 +135,13 @@ pub fn to_price(s: &str) -> Result<f32, String> {
pub fn replace_home(base: &str, arg: &str) -> String { pub fn replace_home(base: &str, arg: &str) -> String {
// the $HOME directory on mac os should be `~/Library` or `~/Library/Application Support` // the $HOME directory on mac os should be `~/Library` or `~/Library/Application Support`
let r = arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()); let r = arg.replace("$HOME", env::home_dir().unwrap().to_str().unwrap());
let r = r.replace("$BASE", base ); let r = r.replace("$BASE", base);
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string() ) r.replace("/", &::std::path::MAIN_SEPARATOR.to_string())
}
pub fn replace_home_for_db(base: &str, local: &str, arg: &str) -> String {
let r = replace_home(base, arg);
r.replace("$LOCAL", local)
} }
/// Flush output buffer. /// Flush output buffer.