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