Base dir option

This commit is contained in:
arkpar 2016-12-15 21:56:45 +01:00
parent 867fdb9eac
commit e2371632c5
14 changed files with 58 additions and 43 deletions

@ -1 +1 @@
Subproject commit e8f4624b7f1a15c63674eecf577c7ab76c3b16be Subproject commit 9028c4801fd39fbb71a9796979182549a24e81c8

View File

@ -180,7 +180,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
let snapshot_path = db_dirs.snapshot_path(); let snapshot_path = db_dirs.snapshot_path();
// execute upgrades // execute upgrades
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path()))); try!(execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path())));
// create dirs used by parity // create dirs used by parity
try!(cmd.dirs.create_dirs(false, false)); try!(cmd.dirs.create_dirs(false, false));
@ -351,7 +351,7 @@ fn start_client(
let snapshot_path = db_dirs.snapshot_path(); let snapshot_path = db_dirs.snapshot_path();
// execute upgrades // execute upgrades
try!(execute_upgrades(&db_dirs, algorithm, compaction.compaction_profile(db_dirs.db_root_path().as_path()))); try!(execute_upgrades(&dirs.base, &db_dirs, algorithm, compaction.compaction_profile(db_dirs.db_root_path().as_path())));
// create dirs used by parity // create dirs used by parity
try!(dirs.create_dirs(false, false)); try!(dirs.create_dirs(false, false));

View File

@ -3,7 +3,8 @@ mode = "last"
mode_timeout = 300 mode_timeout = 300
mode_alarm = 3600 mode_alarm = 3600
chain = "homestead" chain = "homestead"
db_path = "$HOME/.parity" base_path = "$HOME/.parity"
db_path = "$HOME/.parity/chains"
keys_path = "$HOME/.parity/keys" keys_path = "$HOME/.parity/keys"
identity = "" identity = ""

View File

@ -86,8 +86,9 @@ usage! {
flag_mode_timeout: u64 = 300u64, or |c: &Config| otry!(c.parity).mode_timeout.clone(), flag_mode_timeout: u64 = 300u64, or |c: &Config| otry!(c.parity).mode_timeout.clone(),
flag_mode_alarm: u64 = 3600u64, or |c: &Config| otry!(c.parity).mode_alarm.clone(), flag_mode_alarm: u64 = 3600u64, or |c: &Config| otry!(c.parity).mode_alarm.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_db_path: String = default_data_path(), or |c: &Config| otry!(c.parity).db_path.clone(), flag_base_path: String = default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(),
flag_keys_path: String = "$DATA/keys", or |c: &Config| otry!(c.parity).keys_path.clone(), flag_db_path: String = "$BASE/chains", 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(), flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),
// -- Account Options // -- Account Options
@ -106,7 +107,7 @@ usage! {
or |c: &Config| otry!(c.ui).port.clone(), or |c: &Config| otry!(c.ui).port.clone(),
flag_ui_interface: String = "local", flag_ui_interface: String = "local",
or |c: &Config| otry!(c.ui).interface.clone(), or |c: &Config| otry!(c.ui).interface.clone(),
flag_ui_path: String = "$DATA/signer", flag_ui_path: String = "$BASE/signer",
or |c: &Config| otry!(c.ui).path.clone(), or |c: &Config| otry!(c.ui).path.clone(),
// NOTE [todr] For security reasons don't put this to config files // NOTE [todr] For security reasons don't put this to config files
flag_ui_no_validation: bool = false, or |_| None, flag_ui_no_validation: bool = false, or |_| None,
@ -162,7 +163,7 @@ usage! {
// IPC // IPC
flag_no_ipc: bool = false, flag_no_ipc: bool = false,
or |c: &Config| otry!(c.ipc).disable.clone(), or |c: &Config| otry!(c.ipc).disable.clone(),
flag_ipc_path: String = "$DATA/jsonrpc.ipc", flag_ipc_path: String = "$BASE/jsonrpc.ipc",
or |c: &Config| otry!(c.ipc).path.clone(), or |c: &Config| otry!(c.ipc).path.clone(),
flag_ipc_apis: String = "web3,eth,net,parity,parity_accounts,traces,rpc", flag_ipc_apis: String = "web3,eth,net,parity,parity_accounts,traces,rpc",
or |c: &Config| otry!(c.ipc).apis.clone().map(|vec| vec.join(",")), or |c: &Config| otry!(c.ipc).apis.clone().map(|vec| vec.join(",")),
@ -176,7 +177,7 @@ usage! {
or |c: &Config| otry!(c.dapps).interface.clone(), or |c: &Config| otry!(c.dapps).interface.clone(),
flag_dapps_hosts: String = "none", flag_dapps_hosts: String = "none",
or |c: &Config| otry!(c.dapps).hosts.clone().map(|vec| vec.join(",")), or |c: &Config| otry!(c.dapps).hosts.clone().map(|vec| vec.join(",")),
flag_dapps_path: String = "$DATA/dapps", flag_dapps_path: String = "$BASE/dapps",
or |c: &Config| otry!(c.dapps).path.clone(), or |c: &Config| otry!(c.dapps).path.clone(),
flag_dapps_user: Option<String> = None, flag_dapps_user: Option<String> = None,
or |c: &Config| otry!(c.dapps).user.clone().map(Some), or |c: &Config| otry!(c.dapps).user.clone().map(Some),
@ -277,7 +278,7 @@ usage! {
or |c: &Config| otry!(c.vm).jit.clone(), or |c: &Config| otry!(c.vm).jit.clone(),
// -- Miscellaneous Options // -- Miscellaneous Options
flag_config: String = "$DATA/config.toml", or |_| None, flag_config: String = "$BASE/config.toml", or |_| None,
flag_logging: Option<String> = None, flag_logging: Option<String> = None,
or |c: &Config| otry!(c.misc).logging.clone().map(Some), or |c: &Config| otry!(c.misc).logging.clone().map(Some),
flag_log_file: Option<String> = None, flag_log_file: Option<String> = None,
@ -310,6 +311,7 @@ struct Operating {
mode_timeout: Option<u64>, mode_timeout: Option<u64>,
mode_alarm: Option<u64>, mode_alarm: Option<u64>,
chain: Option<String>, chain: Option<String>,
base_path: Option<String>,
db_path: Option<String>, db_path: Option<String>,
keys_path: Option<String>, keys_path: Option<String>,
identity: Option<String>, identity: Option<String>,
@ -534,7 +536,8 @@ mod tests {
flag_mode_timeout: 300u64, flag_mode_timeout: 300u64,
flag_mode_alarm: 3600u64, flag_mode_alarm: 3600u64,
flag_chain: "xyz".into(), flag_chain: "xyz".into(),
flag_db_path: "$HOME/.parity".into(), flag_base_path: "$HOME/.parity".into(),
flag_db_path: "$HOME/.parity/chains".into(),
flag_keys_path: "$HOME/.parity/keys".into(), flag_keys_path: "$HOME/.parity/keys".into(),
flag_identity: "".into(), flag_identity: "".into(),
@ -676,7 +679,7 @@ mod tests {
// -- Miscellaneous Options // -- Miscellaneous Options
flag_version: false, flag_version: false,
flag_config: "$DATA/config.toml".into(), flag_config: "$BASE/config.toml".into(),
flag_logging: Some("own_tx=trace".into()), flag_logging: Some("own_tx=trace".into()),
flag_log_file: Some("/var/log/parity.log".into()), flag_log_file: Some("/var/log/parity.log".into()),
flag_no_color: false, flag_no_color: false,
@ -708,6 +711,7 @@ mod tests {
mode_timeout: Some(15u64), mode_timeout: Some(15u64),
mode_alarm: Some(10u64), mode_alarm: Some(10u64),
chain: Some("./chain.json".into()), chain: Some("./chain.json".into()),
base_path: None,
db_path: None, db_path: None,
keys_path: None, keys_path: None,
identity: None, identity: None,

View File

@ -38,7 +38,9 @@ Operating Options:
JSON chain specification file or olympic, frontier, JSON chain specification file or olympic, frontier,
homestead, mainnet, morden, ropsten, classic, expanse, homestead, mainnet, morden, ropsten, classic, expanse,
testnet or dev (default: {flag_chain}). testnet or dev (default: {flag_chain}).
-d --db-path PATH Specify the database & configuration directory path -d --base-path PATH Specify the base data storage path.
(default: {flag_base_path}).
--db-path PATH Specify the database directory path
(default: {flag_db_path}). (default: {flag_db_path}).
--keys-path PATH Specify the path for JSON key files to be found --keys-path PATH Specify the path for JSON key files to be found
(default: {flag_keys_path}). (default: {flag_keys_path}).

View File

@ -589,7 +589,7 @@ impl Configuration {
ret.snapshot_peers = self.snapshot_peers(); ret.snapshot_peers = self.snapshot_peers();
ret.allow_ips = try!(self.allow_ips()); ret.allow_ips = try!(self.allow_ips());
ret.max_pending_peers = self.max_pending_peers(); ret.max_pending_peers = self.max_pending_peers();
let mut net_path = PathBuf::from(self.directories().data); let mut net_path = PathBuf::from(self.directories().base);
net_path.push("network"); net_path.push("network");
ret.config_path = Some(net_path.to_str().unwrap().to_owned()); ret.config_path = Some(net_path.to_str().unwrap().to_owned());
ret.reserved_nodes = try!(self.init_reserved_nodes()); ret.reserved_nodes = try!(self.init_reserved_nodes());
@ -683,8 +683,9 @@ impl Configuration {
fn directories(&self) -> Directories { fn directories(&self) -> Directories {
use util::path; use util::path;
let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_db_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 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);
@ -706,7 +707,8 @@ impl Configuration {
Directories { Directories {
keys: keys_path, keys: keys_path,
data: data_path, base: data_path,
db: db_path,
dapps: dapps_path, dapps: dapps_path,
signer: ui_path, signer: ui_path,
} }
@ -716,7 +718,7 @@ impl Configuration {
if self.args.flag_geth { if self.args.flag_geth {
geth_ipc_path(self.args.flag_testnet) geth_ipc_path(self.args.flag_testnet)
} else { } else {
parity_ipc_path(&self.directories().data, &self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone())) parity_ipc_path(&self.directories().base, &self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone()))
} }
} }

View File

@ -43,7 +43,7 @@ impl Default for Configuration {
hosts: Some(Vec::new()), hosts: Some(Vec::new()),
user: None, user: None,
pass: None, pass: None,
dapps_path: replace_home(&data_dir, "$DATA/dapps"), dapps_path: replace_home(&data_dir, "$BASE/dapps"),
} }
} }
} }

View File

@ -27,7 +27,8 @@ const LEGACY_CLIENT_DB_VER_STR: &'static str = "5.3";
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Directories { pub struct Directories {
pub data: String, pub base: String,
pub db: String,
pub keys: String, pub keys: String,
pub signer: String, pub signer: String,
pub dapps: String, pub dapps: String,
@ -37,17 +38,19 @@ impl Default for Directories {
fn default() -> Self { fn default() -> Self {
let data_dir = default_data_path(); let data_dir = default_data_path();
Directories { Directories {
data: replace_home(&data_dir, "$DATA"), base: replace_home(&data_dir, "$BASE"),
keys: replace_home(&data_dir, "$DATA/keys"), db: replace_home(&data_dir, "$BASE/chains"),
signer: replace_home(&data_dir, "$DATA/signer"), keys: replace_home(&data_dir, "$BASE/keys"),
dapps: replace_home(&data_dir, "$DATA/dapps"), signer: replace_home(&data_dir, "$BASE/signer"),
dapps: replace_home(&data_dir, "$BASE/dapps"),
} }
} }
} }
impl Directories { impl Directories {
pub fn create_dirs(&self, dapps_enabled: bool, signer_enabled: bool) -> Result<(), String> { pub fn create_dirs(&self, dapps_enabled: bool, signer_enabled: bool) -> Result<(), String> {
try!(fs::create_dir_all(&self.data).map_err(|e| e.to_string())); try!(fs::create_dir_all(&self.base).map_err(|e| e.to_string()));
try!(fs::create_dir_all(&self.db).map_err(|e| e.to_string()));
try!(fs::create_dir_all(&self.keys).map_err(|e| e.to_string())); try!(fs::create_dir_all(&self.keys).map_err(|e| e.to_string()));
if signer_enabled { if signer_enabled {
try!(fs::create_dir_all(&self.signer).map_err(|e| e.to_string())); try!(fs::create_dir_all(&self.signer).map_err(|e| e.to_string()));
@ -61,7 +64,8 @@ impl Directories {
/// Database paths. /// Database paths.
pub fn database(&self, genesis_hash: H256, fork_name: Option<String>, spec_name: String) -> DatabaseDirectories { pub fn database(&self, genesis_hash: H256, fork_name: Option<String>, spec_name: String) -> DatabaseDirectories {
DatabaseDirectories { DatabaseDirectories {
path: self.data.clone(), path: self.db.clone(),
legacy_path: self.base.clone(),
genesis_hash: genesis_hash, genesis_hash: genesis_hash,
fork_name: fork_name, fork_name: fork_name,
spec_name: spec_name, spec_name: spec_name,
@ -70,14 +74,14 @@ impl Directories {
/// Get the ipc sockets path /// Get the ipc sockets path
pub fn ipc_path(&self) -> PathBuf { pub fn ipc_path(&self) -> PathBuf {
let mut dir = Path::new(&self.data).to_path_buf(); let mut dir = Path::new(&self.base).to_path_buf();
dir.push("ipc"); dir.push("ipc");
dir dir
} }
// TODO: remove in 1.7 // TODO: remove in 1.7
pub fn legacy_keys_path(&self, testnet: bool) -> PathBuf { pub fn legacy_keys_path(&self, testnet: bool) -> PathBuf {
let mut dir = Path::new(&self.data).to_path_buf(); let mut dir = Path::new(&self.base).to_path_buf();
if testnet { if testnet {
dir.push("testnet_keys"); dir.push("testnet_keys");
} else { } else {
@ -96,6 +100,7 @@ impl Directories {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct DatabaseDirectories { pub struct DatabaseDirectories {
pub path: String, pub path: String,
pub legacy_path: String,
pub genesis_hash: H256, pub genesis_hash: H256,
pub fork_name: Option<String>, pub fork_name: Option<String>,
pub spec_name: String, pub spec_name: String,
@ -105,14 +110,13 @@ impl DatabaseDirectories {
/// Base DB directory for the given fork. /// Base DB directory for the given fork.
// TODO: remove in 1.7 // TODO: remove in 1.7
pub fn legacy_fork_path(&self) -> PathBuf { pub fn legacy_fork_path(&self) -> PathBuf {
let mut dir = Path::new(&self.path).to_path_buf(); let mut dir = Path::new(&self.legacy_path).to_path_buf();
dir.push(format!("{:?}{}", H64::from(self.genesis_hash), self.fork_name.as_ref().map(|f| format!("-{}", f)).unwrap_or_default())); dir.push(format!("{:?}{}", H64::from(self.genesis_hash), self.fork_name.as_ref().map(|f| format!("-{}", f)).unwrap_or_default()));
dir dir
} }
pub fn spec_root_path(&self) -> PathBuf { pub fn spec_root_path(&self) -> PathBuf {
let mut dir = Path::new(&self.path).to_path_buf(); let mut dir = Path::new(&self.path).to_path_buf();
dir.push("chains");
dir.push(&self.spec_name); dir.push(&self.spec_name);
dir dir
} }
@ -204,10 +208,11 @@ mod tests {
fn test_default_directories() { fn test_default_directories() {
let data_dir = super::default_data_path(); let data_dir = super::default_data_path();
let expected = Directories { let expected = Directories {
data: replace_home(&data_dir, "$DATA"), base: replace_home(&data_dir, "$BASE"),
keys: replace_home(&data_dir, "$DATA/keys"), db: replace_home(&data_dir, "$BASE/chains"),
signer: replace_home(&data_dir, "$DATA/signer"), keys: replace_home(&data_dir, "$BASE/keys"),
dapps: replace_home(&data_dir, "$DATA/dapps"), signer: replace_home(&data_dir, "$BASE/signer"),
dapps: replace_home(&data_dir, "$BASE/dapps"),
}; };
assert_eq!(expected, Directories::default()); assert_eq!(expected, Directories::default());
} }

View File

@ -135,7 +135,7 @@ 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("$DATA", base ); let r = r.replace("$BASE", base );
r.replace("/", &::std::path::MAIN_SEPARATOR.to_string() ) r.replace("/", &::std::path::MAIN_SEPARATOR.to_string() )
} }
@ -188,7 +188,7 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
pub fn default_network_config() -> ::ethsync::NetworkConfiguration { pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
use ethsync::{NetworkConfiguration, AllowIP}; use ethsync::{NetworkConfiguration, AllowIP};
NetworkConfiguration { NetworkConfiguration {
config_path: Some(replace_home(&::dir::default_data_path(), "$DATA/network")), config_path: Some(replace_home(&::dir::default_data_path(), "$BASE/network")),
net_config_path: None, net_config_path: None,
listen_address: Some("0.0.0.0:30303".into()), listen_address: Some("0.0.0.0:30303".into()),
public_address: None, public_address: None,
@ -257,12 +257,13 @@ pub fn to_client_config(
} }
pub fn execute_upgrades( pub fn execute_upgrades(
base_path: &str,
dirs: &DatabaseDirectories, dirs: &DatabaseDirectories,
pruning: Algorithm, pruning: Algorithm,
compaction_profile: CompactionProfile compaction_profile: CompactionProfile
) -> Result<(), String> { ) -> Result<(), String> {
upgrade_data_paths(dirs, pruning); upgrade_data_paths(base_path, dirs, pruning);
match upgrade(Some(&dirs.path)) { match upgrade(Some(&dirs.path)) {
Ok(upgrades_applied) if upgrades_applied > 0 => { Ok(upgrades_applied) if upgrades_applied > 0 => {

View File

@ -62,7 +62,7 @@ impl Default for IpcConfiguration {
let data_dir = default_data_path(); let data_dir = default_data_path();
IpcConfiguration { IpcConfiguration {
enabled: true, enabled: true,
socket_addr: parity_ipc_path(&data_dir, "$DATA/jsonrpc.ipc"), socket_addr: parity_ipc_path(&data_dir, "$BASE/jsonrpc.ipc"),
apis: ApiSet::IpcContext, apis: ApiSet::IpcContext,
} }
} }

View File

@ -164,7 +164,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
let snapshot_path = db_dirs.snapshot_path(); let snapshot_path = db_dirs.snapshot_path();
// execute upgrades // execute upgrades
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path()))); try!(execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path())));
// create dirs used by parity // create dirs used by parity
try!(cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.signer_conf.enabled)); try!(cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.signer_conf.enabled));

View File

@ -44,7 +44,7 @@ impl Default for Configuration {
enabled: true, enabled: true,
port: 8180, port: 8180,
interface: "127.0.0.1".into(), interface: "127.0.0.1".into(),
signer_path: replace_home(&data_dir, "$DATA/signer"), signer_path: replace_home(&data_dir, "$BASE/signer"),
skip_origin_validation: false, skip_origin_validation: false,
} }
} }

View File

@ -167,7 +167,7 @@ impl SnapshotCommand {
let snapshot_path = db_dirs.snapshot_path(); let snapshot_path = db_dirs.snapshot_path();
// execute upgrades // execute upgrades
try!(execute_upgrades(&db_dirs, algorithm, self.compaction.compaction_profile(db_dirs.db_root_path().as_path()))); try!(execute_upgrades(&self.dirs.base, &db_dirs, algorithm, self.compaction.compaction_profile(db_dirs.db_root_path().as_path())));
// prepare client config // prepare client config
let client_config = to_client_config(&self.cache_config, Mode::Active, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true); let client_config = to_client_config(&self.cache_config, Mode::Active, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true);

View File

@ -200,11 +200,11 @@ fn upgrade_user_defaults(dirs: &DatabaseDirectories) {
} }
} }
pub fn upgrade_data_paths(dirs: &DatabaseDirectories, pruning: Algorithm) { pub fn upgrade_data_paths(base_path: &str, dirs: &DatabaseDirectories, pruning: Algorithm) {
let legacy_root_path = replace_home("", "$HOME/.parity"); let legacy_root_path = replace_home("", "$HOME/.parity");
let default_path = default_data_path(); let default_path = default_data_path();
if legacy_root_path != dirs.path && dirs.path == default_path { if legacy_root_path != base_path && base_path == default_path {
upgrade_dir_location(&PathBuf::from(legacy_root_path), &PathBuf::from(&dirs.path)); upgrade_dir_location(&PathBuf::from(legacy_root_path), &PathBuf::from(&base_path));
} }
upgrade_dir_location(&dirs.legacy_version_path(pruning), &dirs.db_path(pruning)); upgrade_dir_location(&dirs.legacy_version_path(pruning), &dirs.db_path(pruning));
upgrade_dir_location(&dirs.legacy_snapshot_path(), &dirs.snapshot_path()); upgrade_dir_location(&dirs.legacy_snapshot_path(), &dirs.snapshot_path());