Merge pull request #911 from matthiasbeyer/libimagstore/storeid-exists-interface-result

Redefine return type of StoreId::exists()
This commit is contained in:
Matthias Beyer 2017-04-22 11:20:50 +02:00 committed by GitHub
commit 5b93f3848c
4 changed files with 26 additions and 14 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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> {

View File

@ -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)
}
}
}
}