using db_path directory

This commit is contained in:
NikVolf 2016-04-15 02:49:42 +03:00
parent 9b2f545391
commit 222a1bd29b
2 changed files with 20 additions and 15 deletions

View File

@ -601,6 +601,18 @@ impl Configuration {
print_version(); print_version();
return; 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 { if self.args.cmd_daemon {
Daemonize::new() Daemonize::new()
.pid_file(self.args.arg_pid_file.clone()) .pid_file(self.args.arg_pid_file.clone())
@ -814,16 +826,6 @@ fn die_with_io_error(e: std::io::Error) -> ! {
} }
fn main() { 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(); Configuration::parse().execute();
} }

View File

@ -92,11 +92,14 @@ fn upgrade_from_version(previous_version: &Version) -> Result<usize, Error> {
Ok(count) Ok(count)
} }
fn with_locked_version<F>(script: F) -> Result<usize, Error> fn with_locked_version<F>(db_path: Option<&str>, script: F) -> Result<usize, Error>
where F: Fn(&Version) -> Result<usize, Error> where F: Fn(&Version) -> Result<usize, Error>
{ {
let mut path = db_path.map_or({
let mut path = env::home_dir().expect("Applications should have a home dir"); let mut path = env::home_dir().expect("Applications should have a home dir");
path.push(".parity"); path.push(".parity");
path
}, |s| ::std::path::PathBuf::from(s));
try!(create_dir_all(&path).map_err(|_| Error::CannotCreateConfigPath)); try!(create_dir_all(&path).map_err(|_| Error::CannotCreateConfigPath));
path.push("ver.lock"); path.push("ver.lock");
@ -118,8 +121,8 @@ fn with_locked_version<F>(script: F) -> Result<usize, Error>
result result
} }
pub fn upgrade() -> Result<usize, Error> { pub fn upgrade(db_path: Option<&str>) -> Result<usize, Error> {
with_locked_version(|ver| { with_locked_version(db_path, |ver| {
upgrade_from_version(ver) upgrade_from_version(ver)
}) })
} }