reducing code
This commit is contained in:
parent
1d09844950
commit
8ecbb53e99
@ -97,23 +97,19 @@ fn with_locked_version<F>(script: F) -> Result<usize, Error>
|
|||||||
path.push(".parity");
|
path.push(".parity");
|
||||||
path.push("ver.lock");
|
path.push("ver.lock");
|
||||||
|
|
||||||
let version: Option<Version> = {
|
let version =
|
||||||
match File::open(&path) {
|
File::open(&path).ok().and_then(|ref mut file|
|
||||||
Ok(mut file) => {
|
{
|
||||||
let mut version_string = String::new();
|
let mut version_string = String::new();
|
||||||
match file.read_to_string(&mut version_string) {
|
file.read_to_string(&mut version_string)
|
||||||
Ok(_) => Some(Version::parse(&version_string).unwrap()),
|
.ok()
|
||||||
Err(_) => None
|
.and_then(|_| Version::parse(&version_string).ok())
|
||||||
}
|
})
|
||||||
},
|
.unwrap_or_else(|| Version::parse("0.9.0").unwrap());
|
||||||
Err(_) => None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let effective_version = version.unwrap_or_else(|| Version::parse("0.9.0").unwrap());
|
|
||||||
|
|
||||||
let script_result = {
|
let script_result = {
|
||||||
let mut lock = try!(File::create(&path).map_err(|_| Error::CannotLockVersionFile));
|
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();
|
let written_version = Version::parse(CURRENT_VERSION).unwrap();
|
||||||
try!(lock.write_all(written_version.to_string().as_bytes()).map_err(|_| Error::CannotUpdateVersionFile));
|
try!(lock.write_all(written_version.to_string().as_bytes()).map_err(|_| Error::CannotUpdateVersionFile));
|
||||||
|
Loading…
Reference in New Issue
Block a user