reducing code

This commit is contained in:
NikVolf 2016-04-12 06:19:15 +03:00
parent 1d09844950
commit 8ecbb53e99

View File

@ -97,23 +97,19 @@ fn with_locked_version<F>(script: F) -> Result<usize, Error>
path.push(".parity");
path.push("ver.lock");
let version: Option<Version> = {
match File::open(&path) {
Ok(mut file) => {
let version =
File::open(&path).ok().and_then(|ref mut file|
{
let mut version_string = String::new();
match file.read_to_string(&mut version_string) {
Ok(_) => Some(Version::parse(&version_string).unwrap()),
Err(_) => None
}
},
Err(_) => None
}
};
let effective_version = version.unwrap_or_else(|| Version::parse("0.9.0").unwrap());
file.read_to_string(&mut version_string)
.ok()
.and_then(|_| Version::parse(&version_string).ok())
})
.unwrap_or_else(|| Version::parse("0.9.0").unwrap());
let script_result = {
let mut lock = try!(File::create(&path).map_err(|_| Error::CannotLockVersionFile));
let result = script(&effective_version);
let result = script(&version);
let written_version = Version::parse(CURRENT_VERSION).unwrap();
try!(lock.write_all(written_version.to_string().as_bytes()).map_err(|_| Error::CannotUpdateVersionFile));