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 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 libimagstore::storeid::StoreId;
use util::Unwrap; use util::Unwrap;
@ -118,7 +118,15 @@ methods!(
} }
fn r_storeid_exists() -> Boolean { 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 { 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>>> { 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 id = try!(id.into_storeid()).with_base(self.path().clone());
let exists = try!(self.entries let exists = try!(id.exists()) || try!(self.entries
.read() .read()
.map(|map| map.contains_key(&id)) .map(|map| map.contains_key(&id))
.map_err(|_| SE::new(SEK::LockPoisoned, None)) .map_err(|_| SE::new(SEK::LockPoisoned, None))
.map_err_into(SEK::GetCallError) .map_err_into(SEK::GetCallError)
); );
if !exists && !id.exists() { if !exists {
debug!("Does not exist in internal cache or filesystem: {:?}", id); debug!("Does not exist in internal cache or filesystem: {:?}", id);
return Ok(None); return Ok(None);
} }

View File

@ -95,9 +95,8 @@ impl StoreId {
Ok(base) Ok(base)
} }
pub fn exists(&self) -> bool { pub fn exists(&self) -> Result<bool> {
// TODO: hiding error here. self.clone().into_pathbuf().map(|pb| pb.exists())
self.clone().into_pathbuf().map(|pb| pb.exists()).unwrap_or(false)
} }
pub fn to_str(&self) -> Result<String> { pub fn to_str(&self) -> Result<String> {

View File

@ -68,20 +68,25 @@ impl HookDataAccessorProvider for LinkedEntriesExistHook {
impl NonMutableHookDataAccessor for LinkedEntriesExistHook { impl NonMutableHookDataAccessor for LinkedEntriesExistHook {
fn access(&self, fle: &FileLockEntry) -> HookResult<()> { fn access(&self, fle: &FileLockEntry) -> HookResult<()> {
use libimagstore::hook::error::HookErrorKind;
use libimagstore::hook::error::MapErrInto;
debug!("[LINKVERIFY HOOK] {:?}", fle.get_location()); debug!("[LINKVERIFY HOOK] {:?}", fle.get_location());
let _ = fle.get_internal_links() match fle.get_internal_links() {
.map(|links| { Ok(links) => {
for link in 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); warn!("File link does not exist: {:?} -> {:?}", fle.get_location(), link);
} }
} }
}) Ok(())
.map_err(|e| { },
Err(e) => {
warn!("Couldn't execute Link-Verify hook"); warn!("Couldn't execute Link-Verify hook");
trace_error(&e); trace_error(&e);
}); Err(e).map_err_into(HookErrorKind::HookExecutionError)
Ok(()) }
}
} }
} }