Merge pull request #960 from ethcore/upgrade-path

using db_path directory when upgrading
This commit is contained in:
Arkadiy Paronyan 2016-04-15 16:30:44 +02:00
commit 38fa25edbe
2 changed files with 20 additions and 15 deletions

View File

@ -606,6 +606,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())
@ -819,16 +831,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();
}

View File

@ -92,11 +92,14 @@ fn upgrade_from_version(previous_version: &Version) -> Result<usize, Error> {
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>
{
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<F>(script: F) -> Result<usize, Error>
result
}
pub fn upgrade() -> Result<usize, Error> {
with_locked_version(|ver| {
pub fn upgrade(db_path: Option<&str>) -> Result<usize, Error> {
with_locked_version(db_path, |ver| {
upgrade_from_version(ver)
})
}