Merge pull request #271 from matthiasbeyer/libimagstore/debugging
Libimagstore/debugging
This commit is contained in:
commit
c03625dfae
2 changed files with 40 additions and 3 deletions
|
@ -20,6 +20,7 @@ pub enum StoreErrorKind {
|
|||
IoError,
|
||||
StorePathExists,
|
||||
StorePathCreate,
|
||||
LockError,
|
||||
LockPoisoned,
|
||||
EntryAlreadyBorrowed,
|
||||
EntryAlreadyExists,
|
||||
|
@ -29,6 +30,7 @@ pub enum StoreErrorKind {
|
|||
HeaderKeyNotFound,
|
||||
HeaderTypeFailure,
|
||||
HookRegisterError,
|
||||
AspectNameNotFoundError,
|
||||
HookExecutionError,
|
||||
PreHookExecuteError,
|
||||
PostHookExecuteError,
|
||||
|
@ -50,6 +52,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
|
|||
&StoreErrorKind::IoError => "File Error",
|
||||
&StoreErrorKind::StorePathExists => "Store path exists",
|
||||
&StoreErrorKind::StorePathCreate => "Store path create",
|
||||
&StoreErrorKind::LockError => "Error locking datastructure",
|
||||
&StoreErrorKind::LockPoisoned
|
||||
=> "The internal Store Lock has been poisoned",
|
||||
&StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed",
|
||||
|
@ -60,6 +63,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
|
|||
&StoreErrorKind::HeaderKeyNotFound => "Header Key not found",
|
||||
&StoreErrorKind::HeaderTypeFailure => "Header type is wrong",
|
||||
&StoreErrorKind::HookRegisterError => "Hook register error",
|
||||
&StoreErrorKind::AspectNameNotFoundError => "Aspect name not found",
|
||||
&StoreErrorKind::HookExecutionError => "Hook execution error",
|
||||
&StoreErrorKind::PreHookExecuteError => "Pre-Hook execution error",
|
||||
&StoreErrorKind::PostHookExecuteError => "Post-Hook execution error",
|
||||
|
|
|
@ -7,11 +7,15 @@ use std::sync::Arc;
|
|||
use std::sync::RwLock;
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::{Seek, SeekFrom};
|
||||
use std::io::Write;
|
||||
use std::convert::From;
|
||||
use std::convert::Into;
|
||||
use std::sync::Mutex;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::fmt::Formatter;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Error as FMTError;
|
||||
|
||||
use toml::{Table, Value};
|
||||
use regex::Regex;
|
||||
|
@ -33,7 +37,7 @@ use hook::Hook;
|
|||
pub type Result<T> = RResult<T, StoreError>;
|
||||
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum StoreEntryStatus {
|
||||
Present,
|
||||
Borrowed
|
||||
|
@ -41,6 +45,7 @@ enum StoreEntryStatus {
|
|||
|
||||
/// A store entry, depending on the option type it is either borrowed currently
|
||||
/// or not.
|
||||
#[derive(Debug)]
|
||||
struct StoreEntry {
|
||||
id: StoreId,
|
||||
file: LazyFile,
|
||||
|
@ -436,7 +441,7 @@ impl Store {
|
|||
let guard = guard
|
||||
.deref()
|
||||
.lock()
|
||||
.map_err(|_| StoreError::new(StoreErrorKind::HookRegisterError, None));
|
||||
.map_err(|_| StoreError::new(StoreErrorKind::LockError, None));
|
||||
|
||||
if guard.is_err() {
|
||||
return Err(StoreError::new(StoreErrorKind::HookRegisterError,
|
||||
|
@ -450,7 +455,9 @@ impl Store {
|
|||
return Ok(());
|
||||
}
|
||||
}
|
||||
return Err(StoreError::new(StoreErrorKind::HookRegisterError, None));
|
||||
|
||||
let annfe = StoreError::new(StoreErrorKind::AspectNameNotFoundError, None);
|
||||
return Err(StoreError::new(StoreErrorKind::HookRegisterError, Some(Box::new(annfe))));
|
||||
}
|
||||
|
||||
fn get_config_for_hook(&self, name: &str) -> Option<&Value> {
|
||||
|
@ -503,6 +510,32 @@ impl Store {
|
|||
|
||||
}
|
||||
|
||||
impl Debug for Store {
|
||||
|
||||
fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FMTError> {
|
||||
try!(write!(fmt, " --- Store ---\n"));
|
||||
try!(write!(fmt, "\n"));
|
||||
try!(write!(fmt, " - location : {:?}\n", self.location));
|
||||
try!(write!(fmt, " - configuration : {:?}\n", self.configuration));
|
||||
try!(write!(fmt, " - pre_read_aspects : {:?}\n", self.pre_read_aspects ));
|
||||
try!(write!(fmt, " - post_read_aspects : {:?}\n", self.post_read_aspects ));
|
||||
try!(write!(fmt, " - pre_create_aspects : {:?}\n", self.pre_create_aspects ));
|
||||
try!(write!(fmt, " - post_create_aspects : {:?}\n", self.post_create_aspects ));
|
||||
try!(write!(fmt, " - pre_retrieve_aspects : {:?}\n", self.pre_retrieve_aspects ));
|
||||
try!(write!(fmt, " - post_retrieve_aspects : {:?}\n", self.post_retrieve_aspects ));
|
||||
try!(write!(fmt, " - pre_update_aspects : {:?}\n", self.pre_update_aspects ));
|
||||
try!(write!(fmt, " - post_update_aspects : {:?}\n", self.post_update_aspects ));
|
||||
try!(write!(fmt, " - pre_delete_aspects : {:?}\n", self.pre_delete_aspects ));
|
||||
try!(write!(fmt, " - post_delete_aspects : {:?}\n", self.post_delete_aspects ));
|
||||
try!(write!(fmt, "\n"));
|
||||
try!(write!(fmt, "Entries:\n"));
|
||||
try!(write!(fmt, "{:?}", self.entries));
|
||||
try!(write!(fmt, "\n"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Drop for Store {
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue