diff --git a/libimagruby/src/storeid.rs b/libimagruby/src/storeid.rs index 58a21501..a08787dd 100644 --- a/libimagruby/src/storeid.rs +++ b/libimagruby/src/storeid.rs @@ -21,7 +21,7 @@ use std::path::PathBuf; -use ruru::{Class, Object, AnyObject, Boolean, RString, NilClass, VerifiedObject}; +use ruru::{Class, Object, AnyObject, Boolean, RString, NilClass, VerifiedObject, VM}; use libimagstore::storeid::StoreId; use util::Unwrap; @@ -118,7 +118,15 @@ methods!( } fn r_storeid_exists() -> Boolean { - Boolean::new(itself.get_data(&*STOREID_WRAPPER).exists()) + use std::error::Error; + + match itself.get_data(&*STOREID_WRAPPER).exists() { + Ok(bool) => Boolean::new(bool), + Err(e) => { + VM::raise(Class::from_existing("RuntimeError"), e.description()); + Boolean::new(false) + } + } } fn r_storeid_to_str() -> AnyObject { diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 6409023a..39f59788 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -552,14 +552,14 @@ impl Store { pub fn get<'a, S: IntoStoreId + Clone>(&'a self, id: S) -> Result>> { let id = try!(id.into_storeid()).with_base(self.path().clone()); - let exists = try!(self.entries + let exists = try!(id.exists()) || try!(self.entries .read() .map(|map| map.contains_key(&id)) .map_err(|_| SE::new(SEK::LockPoisoned, None)) .map_err_into(SEK::GetCallError) ); - if !exists && !id.exists() { + if !exists { debug!("Does not exist in internal cache or filesystem: {:?}", id); return Ok(None); } diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 72e75d3e..13dfcf18 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -95,9 +95,8 @@ impl StoreId { Ok(base) } - pub fn exists(&self) -> bool { - // TODO: hiding error here. - self.clone().into_pathbuf().map(|pb| pb.exists()).unwrap_or(false) + pub fn exists(&self) -> Result { + self.clone().into_pathbuf().map(|pb| pb.exists()) } pub fn to_str(&self) -> Result { diff --git a/libimagstorestdhook/src/linkverify.rs b/libimagstorestdhook/src/linkverify.rs index 3b3c3cea..79194797 100644 --- a/libimagstorestdhook/src/linkverify.rs +++ b/libimagstorestdhook/src/linkverify.rs @@ -68,20 +68,25 @@ impl HookDataAccessorProvider for LinkedEntriesExistHook { impl NonMutableHookDataAccessor for LinkedEntriesExistHook { fn access(&self, fle: &FileLockEntry) -> HookResult<()> { + use libimagstore::hook::error::HookErrorKind; + use libimagstore::hook::error::MapErrInto; + debug!("[LINKVERIFY HOOK] {:?}", fle.get_location()); - let _ = fle.get_internal_links() - .map(|links| { + match fle.get_internal_links() { + Ok(links) => { for link in links { - if !link.exists() { + if !try!(link.exists().map_err_into(HookErrorKind::HookExecutionError)) { warn!("File link does not exist: {:?} -> {:?}", fle.get_location(), link); } } - }) - .map_err(|e| { + Ok(()) + }, + Err(e) => { warn!("Couldn't execute Link-Verify hook"); trace_error(&e); - }); - Ok(()) + Err(e).map_err_into(HookErrorKind::HookExecutionError) + } + } } }