From f5985bbffcc2591a2abdd5eb226a9f0b069b5cdc Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 13 Apr 2016 18:02:16 -0700 Subject: [PATCH] Fix upgrade script and make parity run when no .parity dir. --- parity/upgrade.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/parity/upgrade.rs b/parity/upgrade.rs index da01c039e..f53d68b18 100644 --- a/parity/upgrade.rs +++ b/parity/upgrade.rs @@ -18,14 +18,15 @@ use semver::Version; use std::collections::*; -use std::fs::File; +use std::fs::{File, create_dir_all}; use std::env; use std::io::{Read, Write}; #[cfg_attr(feature="dev", allow(enum_variant_names))] #[derive(Debug)] pub enum Error { - CannotLockVersionFile, + CannotCreateConfigPath, + CannotWriteVersionFile, CannotUpdateVersionFile, } @@ -66,7 +67,7 @@ fn dummy_upgrade() -> Result<(), Error> { Ok(()) } -fn push_updrades(upgrades: &mut UpgradeList) +fn push_upgrades(upgrades: &mut UpgradeList) { // dummy upgrade (remove when the first one is in) upgrades.insert( @@ -76,7 +77,7 @@ fn push_updrades(upgrades: &mut UpgradeList) fn upgrade_from_version(previous_version: &Version) -> Result { let mut upgrades = HashMap::new(); - push_updrades(&mut upgrades); + push_upgrades(&mut upgrades); let current_version = Version::parse(CURRENT_VERSION).unwrap(); @@ -96,6 +97,7 @@ fn with_locked_version(script: F) -> Result { let mut path = env::home_dir().expect("Applications should have a home dir"); path.push(".parity"); + try!(create_dir_all(&path).map_err(|_| Error::CannotCreateConfigPath)); path.push("ver.lock"); let version = @@ -108,7 +110,7 @@ fn with_locked_version(script: F) -> Result }) .unwrap_or_else(|| Version::parse("0.9.0").unwrap()); - let mut lock = try!(File::create(&path).map_err(|_| Error::CannotLockVersionFile)); + let mut lock = try!(File::create(&path).map_err(|_| Error::CannotWriteVersionFile)); let result = script(&version); let written_version = Version::parse(CURRENT_VERSION).unwrap();