From 52367edc83d87221826253e0c50b82a2f65c44f7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 13 Oct 2016 14:28:26 +0200 Subject: [PATCH] Remove unwrap()s in file abstraction code --- libimagstore/src/file_abstraction.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libimagstore/src/file_abstraction.rs b/libimagstore/src/file_abstraction.rs index 9a190842..a958b216 100644 --- a/libimagstore/src/file_abstraction.rs +++ b/libimagstore/src/file_abstraction.rs @@ -58,7 +58,7 @@ mod fs { debug!("Getting lazy file: {:?}", self); match *self { FileAbstraction::Absent(ref f) => { - let map = MAP.lock().unwrap(); + let map = try!(MAP.lock().map_err_into(SEK::LockPoisoned)); return map.get(f).cloned().ok_or(SEK::FileNotFound.into_error()); }, }; @@ -67,7 +67,7 @@ mod fs { pub fn write_file_content(&mut self, buf: &[u8]) -> Result<(), SE> { match *self { FileAbstraction::Absent(ref f) => { - let mut map = MAP.lock().unwrap(); + let mut map = try!(MAP.lock().map_err_into(SEK::LockPoisoned)); if let Some(ref mut cur) = map.get_mut(f) { let mut vec = cur.get_mut(); vec.clear(); @@ -82,19 +82,21 @@ mod fs { } pub fn remove_file(path: &PathBuf) -> Result<(), SE> { - MAP.lock().unwrap().remove(path); - Ok(()) + try!(MAP.lock().map_err_into(SEK::LockPoisoned)) + .remove(path) + .map(|_| ()) + .ok_or(SEK::FileNotFound.into_error()) } pub fn copy(from: &PathBuf, to: &PathBuf) -> Result<(), SE> { - let mut map = MAP.lock().unwrap(); + let mut map = try!(MAP.lock().map_err_into(SEK::LockPoisoned)); let a = try!(map.get(from).cloned().ok_or(SEK::FileNotFound.into_error())); map.insert(to.clone(), a); Ok(()) } pub fn rename(from: &PathBuf, to: &PathBuf) -> Result<(), SE> { - let mut map = MAP.lock().unwrap(); + let mut map = try!(MAP.lock().map_err_into(SEK::LockPoisoned)); let a = try!(map.get(from).cloned().ok_or(SEK::FileNotFound.into_error())); map.insert(to.clone(), a); Ok(())