XDG paths
This commit is contained in:
@@ -149,9 +149,6 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
|
||||
// Setup panic handler
|
||||
let panic_handler = PanicHandler::new_in_arc();
|
||||
|
||||
// create dirs used by parity
|
||||
try!(cmd.dirs.create_dirs(false, false));
|
||||
|
||||
// load spec file
|
||||
let spec = try!(cmd.spec.spec());
|
||||
|
||||
@@ -185,6 +182,9 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
|
||||
// execute upgrades
|
||||
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path())));
|
||||
|
||||
// create dirs used by parity
|
||||
try!(cmd.dirs.create_dirs(false, false));
|
||||
|
||||
// prepare client config
|
||||
let mut client_config = to_client_config(
|
||||
&cmd.cache_config,
|
||||
@@ -320,9 +320,6 @@ fn start_client(
|
||||
wal: bool,
|
||||
cache_config: CacheConfig) -> Result<ClientService, String> {
|
||||
|
||||
// create dirs used by parity
|
||||
try!(dirs.create_dirs(false, false));
|
||||
|
||||
// load spec file
|
||||
let spec = try!(spec.spec());
|
||||
|
||||
@@ -356,6 +353,9 @@ fn start_client(
|
||||
// execute upgrades
|
||||
try!(execute_upgrades(&db_dirs, algorithm, compaction.compaction_profile(db_dirs.db_root_path().as_path())));
|
||||
|
||||
// create dirs used by parity
|
||||
try!(dirs.create_dirs(false, false));
|
||||
|
||||
// prepare client config
|
||||
let client_config = to_client_config(&cache_config, Mode::Active, tracing, fat_db, compaction, wal, VMType::default(), "".into(), algorithm, pruning_history, true);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#[macro_use]
|
||||
mod usage;
|
||||
use dir::default_data_path;
|
||||
|
||||
usage! {
|
||||
{
|
||||
@@ -82,7 +83,7 @@ usage! {
|
||||
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_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
|
||||
flag_db_path: String = "$HOME/.parity", or |c: &Config| otry!(c.parity).db_path.clone(),
|
||||
flag_db_path: String = default_data_path(), or |c: &Config| otry!(c.parity).db_path.clone(),
|
||||
flag_keys_path: String = "$DATA/keys", or |c: &Config| otry!(c.parity).keys_path.clone(),
|
||||
flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(),
|
||||
|
||||
|
||||
@@ -739,8 +739,9 @@ mod tests {
|
||||
use ethcore_rpc::NetworkSettings;
|
||||
use ethcore::client::{VMType, BlockId};
|
||||
use ethcore::miner::{MinerOptions, PrioritizationStrategy};
|
||||
use helpers::{replace_home, default_network_config};
|
||||
use helpers::{default_network_config};
|
||||
use run::RunCmd;
|
||||
use dir::Directories;
|
||||
use signer::{Configuration as SignerConfiguration};
|
||||
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat, ExportState};
|
||||
use presale::ImportWallet;
|
||||
@@ -772,7 +773,7 @@ mod tests {
|
||||
let conf = parse(&args);
|
||||
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(AccountCmd::New(NewAccount {
|
||||
iterations: 10240,
|
||||
path: replace_home("", "$HOME/.parity/keys"),
|
||||
path: Directories::default().keys,
|
||||
password_file: None,
|
||||
spec: SpecType::default(),
|
||||
})));
|
||||
@@ -784,7 +785,7 @@ mod tests {
|
||||
let conf = parse(&args);
|
||||
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(
|
||||
AccountCmd::List(ListAccounts {
|
||||
path: replace_home("", "$HOME/.parity/keys"),
|
||||
path: Directories::default().keys,
|
||||
spec: SpecType::default(),
|
||||
})
|
||||
));
|
||||
@@ -796,7 +797,7 @@ mod tests {
|
||||
let conf = parse(&args);
|
||||
assert_eq!(conf.into_command().unwrap().cmd, Cmd::Account(AccountCmd::Import(ImportAccounts {
|
||||
from: vec!["my_dir".into(), "another_dir".into()],
|
||||
to: replace_home("", "$HOME/.parity/keys"),
|
||||
to: Directories::default().keys,
|
||||
spec: SpecType::default(),
|
||||
})));
|
||||
}
|
||||
@@ -807,7 +808,7 @@ mod tests {
|
||||
let conf = parse(&args);
|
||||
assert_eq!(conf.into_command().unwrap().cmd, Cmd::ImportPresaleWallet(ImportWallet {
|
||||
iterations: 10240,
|
||||
path: replace_home("", "$HOME/.parity/keys"),
|
||||
path: Directories::default().keys,
|
||||
wallet_path: "my_wallet.json".into(),
|
||||
password_file: Some("pwd".into()),
|
||||
spec: SpecType::default(),
|
||||
@@ -909,7 +910,7 @@ mod tests {
|
||||
fn test_command_signer_new_token() {
|
||||
let args = vec!["parity", "signer", "new-token"];
|
||||
let conf = parse(&args);
|
||||
let expected = replace_home("", "$HOME/.parity/signer");
|
||||
let expected = Directories::default().signer;
|
||||
assert_eq!(conf.into_command().unwrap().cmd, Cmd::SignerToken(SignerConfiguration {
|
||||
enabled: true,
|
||||
signer_path: expected,
|
||||
|
||||
@@ -20,6 +20,7 @@ use rpc_apis;
|
||||
use ethcore::client::Client;
|
||||
use ethsync::SyncProvider;
|
||||
use helpers::replace_home;
|
||||
use dir::default_data_path;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Configuration {
|
||||
@@ -34,6 +35,7 @@ pub struct Configuration {
|
||||
|
||||
impl Default for Configuration {
|
||||
fn default() -> Self {
|
||||
let data_dir = default_data_path();
|
||||
Configuration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
@@ -41,7 +43,7 @@ impl Default for Configuration {
|
||||
hosts: Some(Vec::new()),
|
||||
user: None,
|
||||
pass: None,
|
||||
dapps_path: replace_home("", "$HOME/.parity/dapps"),
|
||||
dapps_path: replace_home(&data_dir, "$DATA/dapps"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use std::path::{PathBuf, Path};
|
||||
use util::{H64, H256};
|
||||
use util::journaldb::Algorithm;
|
||||
use helpers::replace_home;
|
||||
use app_dirs::{AppInfo, get_app_root, AppDataType};
|
||||
|
||||
// this const is irrelevent cause we do have migrations now,
|
||||
// but we still use it for backwards compatibility
|
||||
@@ -34,11 +35,12 @@ pub struct Directories {
|
||||
|
||||
impl Default for Directories {
|
||||
fn default() -> Self {
|
||||
let data_dir = default_data_path();
|
||||
Directories {
|
||||
data: replace_home("", "$HOME/.parity"),
|
||||
keys: replace_home("", "$HOME/.parity/keys"),
|
||||
signer: replace_home("", "$HOME/.parity/signer"),
|
||||
dapps: replace_home("", "$HOME/.parity/dapps"),
|
||||
data: replace_home(&data_dir, "$DATA"),
|
||||
keys: replace_home(&data_dir, "$DATA/keys"),
|
||||
signer: replace_home(&data_dir, "$DATA/signer"),
|
||||
dapps: replace_home(&data_dir, "$DATA/dapps"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,6 +190,11 @@ impl DatabaseDirectories {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_data_path() -> String {
|
||||
let app_info = AppInfo { name: "parity", author: "parity" };
|
||||
get_app_root(AppDataType::UserData, &app_info).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| "$HOME/.parity".to_owned())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Directories;
|
||||
@@ -195,11 +202,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_default_directories() {
|
||||
let data_dir = super::default_data_path();
|
||||
let expected = Directories {
|
||||
data: replace_home("", "$HOME/.parity"),
|
||||
keys: replace_home("", "$HOME/.parity/keys"),
|
||||
signer: replace_home("", "$HOME/.parity/signer"),
|
||||
dapps: replace_home("", "$HOME/.parity/dapps"),
|
||||
data: replace_home(&data_dir, "$DATA"),
|
||||
keys: replace_home(&data_dir, "$DATA/keys"),
|
||||
signer: replace_home(&data_dir, "$DATA/signer"),
|
||||
dapps: replace_home(&data_dir, "$DATA/dapps"),
|
||||
};
|
||||
assert_eq!(expected, Directories::default());
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
|
||||
pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
|
||||
use ethsync::{NetworkConfiguration, AllowIP};
|
||||
NetworkConfiguration {
|
||||
config_path: Some(replace_home("", "$HOME/.parity/network")),
|
||||
config_path: Some(replace_home(&::dir::default_data_path(), "$DATA/network")),
|
||||
net_config_path: None,
|
||||
listen_address: Some("0.0.0.0:30303".into()),
|
||||
public_address: None,
|
||||
|
||||
@@ -54,6 +54,7 @@ extern crate ansi_term;
|
||||
extern crate regex;
|
||||
extern crate isatty;
|
||||
extern crate toml;
|
||||
extern crate app_dirs;
|
||||
|
||||
#[macro_use]
|
||||
extern crate ethcore_util as util;
|
||||
|
||||
@@ -23,6 +23,7 @@ use ethcore_rpc::{RpcServerError, RpcServer as Server, IpcServerError};
|
||||
use rpc_apis;
|
||||
use rpc_apis::ApiSet;
|
||||
use helpers::parity_ipc_path;
|
||||
use dir::default_data_path;
|
||||
|
||||
pub use ethcore_rpc::{IpcServer, Server as HttpServer};
|
||||
|
||||
@@ -58,9 +59,10 @@ pub struct IpcConfiguration {
|
||||
|
||||
impl Default for IpcConfiguration {
|
||||
fn default() -> Self {
|
||||
let data_dir = default_data_path();
|
||||
IpcConfiguration {
|
||||
enabled: true,
|
||||
socket_addr: parity_ipc_path("", "$HOME/.parity/jsonrpc.ipc"),
|
||||
socket_addr: parity_ipc_path(&data_dir, "$DATA/jsonrpc.ipc"),
|
||||
apis: ApiSet::IpcContext,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +130,6 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
// increase max number of open files
|
||||
raise_fd_limit();
|
||||
|
||||
// create dirs used by parity
|
||||
try!(cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.signer_conf.enabled));
|
||||
|
||||
// load spec
|
||||
let spec = try!(cmd.spec.spec());
|
||||
|
||||
@@ -169,6 +166,9 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
// execute upgrades
|
||||
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.db_root_path().as_path())));
|
||||
|
||||
// create dirs used by parity
|
||||
try!(cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.signer_conf.enabled));
|
||||
|
||||
// run in daemon mode
|
||||
if let Some(pid_file) = cmd.daemon {
|
||||
try!(daemonize(pid_file));
|
||||
|
||||
@@ -23,6 +23,7 @@ use util::path::restrict_permissions_owner;
|
||||
use rpc_apis;
|
||||
use ethcore_signer as signer;
|
||||
use helpers::replace_home;
|
||||
use dir::default_data_path;
|
||||
pub use ethcore_signer::Server as SignerServer;
|
||||
|
||||
const CODES_FILENAME: &'static str = "authcodes";
|
||||
@@ -38,11 +39,12 @@ pub struct Configuration {
|
||||
|
||||
impl Default for Configuration {
|
||||
fn default() -> Self {
|
||||
let data_dir = default_data_path();
|
||||
Configuration {
|
||||
enabled: true,
|
||||
port: 8180,
|
||||
interface: "127.0.0.1".into(),
|
||||
signer_path: replace_home("", "$HOME/.parity/signer"),
|
||||
signer_path: replace_home(&data_dir, "$DATA/signer"),
|
||||
skip_origin_validation: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ use std::env;
|
||||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::{PathBuf, Path};
|
||||
use dir::DatabaseDirectories;
|
||||
use dir::{DatabaseDirectories, default_data_path};
|
||||
use helpers::replace_home;
|
||||
use util::journaldb::Algorithm;
|
||||
|
||||
#[cfg_attr(feature="dev", allow(enum_variant_names))]
|
||||
@@ -196,6 +197,11 @@ fn upgrade_user_defaults(dirs: &DatabaseDirectories) {
|
||||
}
|
||||
|
||||
pub fn upgrade_data_paths(dirs: &DatabaseDirectories, pruning: Algorithm) {
|
||||
let legacy_root_path = replace_home("", "$HOME/.parity");
|
||||
let default_path = default_data_path();
|
||||
if legacy_root_path != dirs.path && dirs.path == default_path {
|
||||
upgrade_dir_location(&PathBuf::from(legacy_root_path), &PathBuf::from(&dirs.path));
|
||||
}
|
||||
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_network_path(), &dirs.network_path());
|
||||
|
||||
Reference in New Issue
Block a user