From 222a1bd29b5cfe3ae8f21b71df8a25e7517ea522 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 15 Apr 2016 02:49:42 +0300 Subject: [PATCH] using db_path directory --- parity/main.rs | 22 ++++++++++++---------- parity/upgrade.rs | 13 ++++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/parity/main.rs b/parity/main.rs index 94466e0e2..3a2c41f21 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -601,6 +601,18 @@ impl Configuration { print_version(); return; } + + match ::upgrade::upgrade(Some(&self.path())) { + Ok(upgrades_applied) => { + if upgrades_applied > 0 { + println!("Executed {} upgrade scripts - ok", upgrades_applied); + } + }, + Err(e) => { + die!("Error upgrading parity data: {:?}", e); + } + } + if self.args.cmd_daemon { Daemonize::new() .pid_file(self.args.arg_pid_file.clone()) @@ -814,16 +826,6 @@ fn die_with_io_error(e: std::io::Error) -> ! { } fn main() { - match ::upgrade::upgrade() { - Ok(upgrades_applied) => { - if upgrades_applied > 0 { - println!("Executed {} upgrade scripts - ok", upgrades_applied); - } - }, - Err(e) => { - die!("Error upgrading parity data: {:?}", e); - } - } Configuration::parse().execute(); } diff --git a/parity/upgrade.rs b/parity/upgrade.rs index f53d68b18..b74c17f64 100644 --- a/parity/upgrade.rs +++ b/parity/upgrade.rs @@ -92,11 +92,14 @@ fn upgrade_from_version(previous_version: &Version) -> Result { Ok(count) } -fn with_locked_version(script: F) -> Result +fn with_locked_version(db_path: Option<&str>, script: F) -> Result where F: Fn(&Version) -> Result { - let mut path = env::home_dir().expect("Applications should have a home dir"); - path.push(".parity"); + let mut path = db_path.map_or({ + let mut path = env::home_dir().expect("Applications should have a home dir"); + path.push(".parity"); + path + }, |s| ::std::path::PathBuf::from(s)); try!(create_dir_all(&path).map_err(|_| Error::CannotCreateConfigPath)); path.push("ver.lock"); @@ -118,8 +121,8 @@ fn with_locked_version(script: F) -> Result result } -pub fn upgrade() -> Result { - with_locked_version(|ver| { +pub fn upgrade(db_path: Option<&str>) -> Result { + with_locked_version(db_path, |ver| { upgrade_from_version(ver) }) }