Add StoreIdAccessor trait

This commit is contained in:
Matthias Beyer 2016-03-04 16:48:03 +01:00
parent fa9e8e8192
commit 3e62b71605
2 changed files with 17 additions and 5 deletions

View file

@ -1,5 +1,10 @@
use hook::result::HookResult; use hook::result::HookResult;
use store::FileLockEntry; use store::FileLockEntry;
use storeid::StoreId;
pub trait StoreIdAccessor : Send + Sync {
fn access(&self, &StoreId) -> HookResult<()>;
}
pub trait MutableHookDataAccessor : Send + Sync { pub trait MutableHookDataAccessor : Send + Sync {
fn access_mut(&self, &mut FileLockEntry) -> HookResult<()>; fn access_mut(&self, &mut FileLockEntry) -> HookResult<()>;
@ -10,6 +15,7 @@ pub trait NonMutableHookDataAccessor : Send + Sync {
} }
pub enum HookDataAccessor { pub enum HookDataAccessor {
StoreIdAccess(Box<StoreIdAccessor>),
MutableAccess(Box<MutableHookDataAccessor>), MutableAccess(Box<MutableHookDataAccessor>),
NonMutableAccess(Box<NonMutableHookDataAccessor>), NonMutableAccess(Box<NonMutableHookDataAccessor>),
} }

View file

@ -498,19 +498,25 @@ impl Store {
match accessor.deref() { match accessor.deref() {
&HDA::MutableAccess(ref accessor) => { &HDA::MutableAccess(ref accessor) => {
match acc { match acc {
Ok(mut fle) => accessor.access_mut(&mut fle).and(Ok(fle)), Ok(mut fle) => accessor
Err(e) => Err(e), .access_mut(&mut fle)
.and(Ok(fle))
.map_err(|e| SE::new(SEK::HookExecutionError, Some(Box::new(e)))),
Err(e) => Err(SE::new(SEK::HookExecutionError, Some(Box::new(e)))),
} }
}, },
&HDA::NonMutableAccess(ref accessor) => { &HDA::NonMutableAccess(ref accessor) => {
match acc { match acc {
Ok(mut fle) => accessor.access(&fle).and(Ok(fle)), Ok(mut fle) => accessor
Err(e) => Err(e), .access(&fle)
.and(Ok(fle))
.map_err(|e| SE::new(SEK::HookExecutionError, Some(Box::new(e)))),
Err(e) => Err(SE::new(SEK::HookExecutionError, Some(Box::new(e)))),
} }
}, },
_ => Err(StoreError::new(StoreErrorKind::HookExecutionError, None)),
} }
}) })
.map_err(|e| SE::new(SEK::HookExecutionError, Some(Box::new(e))))
} }
} }