Merge pull request #954 from ethcore/fixupgrade
Fix upgrade script and make parity run when no .parity dir.
This commit is contained in:
commit
01e7d2d872
@ -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<usize, Error> {
|
||||
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<F>(script: F) -> Result<usize, Error>
|
||||
{
|
||||
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<F>(script: F) -> Result<usize, Error>
|
||||
})
|
||||
.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();
|
||||
|
Loading…
Reference in New Issue
Block a user