Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

using db_path directory when upgrading #960

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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();
}
Expand Down
13 changes: 8 additions & 5 deletions parity/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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");

Expand All @@ -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)
})
}