Fix libimagstorestdhook::{flock, linkverify}::* for new StoreId interface
This commit is contained in:
parent
0ebbdaa797
commit
f46d4f4dfd
2 changed files with 10 additions and 17 deletions
|
@ -18,27 +18,23 @@ use libimagstore::store::FileLockEntry;
|
|||
use libimagstore::store::Entry;
|
||||
|
||||
trait EntryFlock {
|
||||
fn lock(&self, store_location: &PathBuf) -> IoResult<()>;
|
||||
fn unlock(&self, store_location: &PathBuf) -> IoResult<()>;
|
||||
fn lock(&self) -> IoResult<()>;
|
||||
fn unlock(&self) -> IoResult<()>;
|
||||
}
|
||||
|
||||
impl EntryFlock for Entry {
|
||||
|
||||
fn lock(&self, store_location: &PathBuf) -> IoResult<()> {
|
||||
fn lock(&self) -> IoResult<()> {
|
||||
use std::fs::File;
|
||||
|
||||
let mut location = store_location.clone();
|
||||
location.push(self.get_location());
|
||||
|
||||
let location : PathBuf = self.get_location().clone().into();
|
||||
File::open(location).and_then(|file| file.lock_exclusive())
|
||||
}
|
||||
|
||||
fn unlock(&self, store_location: &PathBuf) -> IoResult<()> {
|
||||
fn unlock(&self) -> IoResult<()> {
|
||||
use std::fs::File;
|
||||
|
||||
let mut location = store_location.clone();
|
||||
location.push(self.get_location());
|
||||
|
||||
let location : PathBuf = self.get_location().clone().into();
|
||||
File::open(location).and_then(|file| file.unlock())
|
||||
}
|
||||
|
||||
|
@ -60,15 +56,13 @@ fn action_to_str(a: &Action) -> &'static str {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct FlockUpdateHook {
|
||||
action: Action,
|
||||
store_location: PathBuf,
|
||||
}
|
||||
|
||||
impl FlockUpdateHook {
|
||||
|
||||
pub fn new(action: Action, store_location: PathBuf) -> FlockUpdateHook {
|
||||
pub fn new(action: Action) -> FlockUpdateHook {
|
||||
FlockUpdateHook {
|
||||
action: action,
|
||||
store_location: store_location,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +101,7 @@ impl MutableHookDataAccessor for FlockUpdateHook {
|
|||
|
||||
fn access_mut(&self, fle: &mut FileLockEntry) -> HookResult<()> {
|
||||
debug!("[FLOCK HOOK][{}] {:?}", action_to_str(&self.action), fle.get_location());
|
||||
fle.lock(&self.store_location)
|
||||
fle.lock()
|
||||
.map_err(|e| HookError::new(HookErrorKind::HookExecutionError, Some(Box::new(e))))
|
||||
.map(|_| ())
|
||||
}
|
||||
|
@ -118,7 +112,7 @@ impl NonMutableHookDataAccessor for FlockUpdateHook {
|
|||
|
||||
fn access(&self, fle: &FileLockEntry) -> HookResult<()> {
|
||||
debug!("[FLOCK HOOK][{}] {:?}", action_to_str(&self.action), fle.get_location());
|
||||
fle.unlock(&self.store_location)
|
||||
fle.unlock()
|
||||
.map_err(|e| HookError::new(HookErrorKind::HookExecutionError, Some(Box::new(e))))
|
||||
.map(|_| ())
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ impl NonMutableHookDataAccessor for LinkedEntriesExistHook {
|
|||
let _ = fle.get_internal_links()
|
||||
.map(|links| {
|
||||
for link in links {
|
||||
let mut path = self.store_location.clone();
|
||||
path.push(link);
|
||||
let path : PathBuf = link.into();
|
||||
if !path.exists() {
|
||||
warn!("File link does not exist: {:?} -> {:?}", fle.get_location(), path);
|
||||
} else if !path.is_file() {
|
||||
|
|
Loading…
Reference in a new issue