summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-04-22 11:20:50 +0200
committerGitHub <noreply@github.com>2017-04-22 11:20:50 +0200
commit5b93f3848cb60ae76a450f79b6f3bd984847db0e (patch)
tree78801b86f9149c3f4cf118718488cc77f9cf715e
parent6fa281a1a4e0c99b4bcb5a95f016018ef7453cd3 (diff)
parent0525f998c88bafb94625d4e08dd1cedbb87c8a02 (diff)
downloadimag-5b93f3848cb60ae76a450f79b6f3bd984847db0e.zip
imag-5b93f3848cb60ae76a450f79b6f3bd984847db0e.tar.gz
Merge pull request #911 from matthiasbeyer/libimagstore/storeid-exists-interface-result
Redefine return type of StoreId::exists()
-rw-r--r--libimagruby/src/storeid.rs12
-rw-r--r--libimagstore/src/store.rs4
-rw-r--r--libimagstore/src/storeid.rs5
-rw-r--r--libimagstorestdhook/src/linkverify.rs19
4 files changed, 26 insertions, 14 deletions
diff --git a/libimagruby/src/storeid.rs b/libimagruby/src/storeid.rs
index 58a2150..a08787d 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 6409023..39f5978 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<Option<FileLockEntry<'a>>> {
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 72e75d3..13dfcf1 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<bool> {
+ self.clone().into_pathbuf().map(|pb| pb.exists())
}
pub fn to_str(&self) -> Result<String> {
diff --git a/libimagstorestdhook/src/linkverify.rs b/libimagstorestdhook/src/linkverify.rs
index 3b3c3ce..7919479 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)
+ }
+ }
}
}