Fix upgrade script and make parity run when no .parity dir.

This commit is contained in:
Gav Wood 2016-04-13 18:02:16 -07:00
parent 32ca8066e9
commit f5985bbffc

View File

@ -18,14 +18,15 @@
use semver::Version; use semver::Version;
use std::collections::*; use std::collections::*;
use std::fs::File; use std::fs::{File, create_dir_all};
use std::env; use std::env;
use std::io::{Read, Write}; use std::io::{Read, Write};
#[cfg_attr(feature="dev", allow(enum_variant_names))] #[cfg_attr(feature="dev", allow(enum_variant_names))]
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
CannotLockVersionFile, CannotCreateConfigPath,
CannotWriteVersionFile,
CannotUpdateVersionFile, CannotUpdateVersionFile,
} }
@ -66,7 +67,7 @@ fn dummy_upgrade() -> Result<(), Error> {
Ok(()) Ok(())
} }
fn push_updrades(upgrades: &mut UpgradeList) fn push_upgrades(upgrades: &mut UpgradeList)
{ {
// dummy upgrade (remove when the first one is in) // dummy upgrade (remove when the first one is in)
upgrades.insert( upgrades.insert(
@ -76,7 +77,7 @@ fn push_updrades(upgrades: &mut UpgradeList)
fn upgrade_from_version(previous_version: &Version) -> Result<usize, Error> { fn upgrade_from_version(previous_version: &Version) -> Result<usize, Error> {
let mut upgrades = HashMap::new(); let mut upgrades = HashMap::new();
push_updrades(&mut upgrades); push_upgrades(&mut upgrades);
let current_version = Version::parse(CURRENT_VERSION).unwrap(); let current_version = Version::parse(CURRENT_VERSION).unwrap();
@ -96,6 +97,7 @@ fn with_locked_version<F>(script: F) -> Result<usize, Error>
{ {
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");
try!(create_dir_all(&path).map_err(|_| Error::CannotCreateConfigPath));
path.push("ver.lock"); path.push("ver.lock");
let version = let version =
@ -108,7 +110,7 @@ fn with_locked_version<F>(script: F) -> Result<usize, Error>
}) })
.unwrap_or_else(|| Version::parse("0.9.0").unwrap()); .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 result = script(&version);
let written_version = Version::parse(CURRENT_VERSION).unwrap(); let written_version = Version::parse(CURRENT_VERSION).unwrap();