Merge pull request #262 from matthiasbeyer/libimagstore/warn-to-err
Libimagstore/warn-to-err
This commit is contained in:
commit
be551feb83
7 changed files with 29 additions and 78 deletions
|
@ -1,5 +1,4 @@
|
|||
use toml::Value;
|
||||
use hook::position::HookPosition;
|
||||
|
||||
/// Check whether the configuration is valid for the store
|
||||
///
|
||||
|
@ -48,10 +47,6 @@ pub fn config_is_valid(config: &Option<Value>) -> bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
fn has_key_with_map(v: &BTreeMap<String, Value>, key: &str) -> bool {
|
||||
v.get(key).map(|t| match t { &Value::Table(_) => true, _ => false }).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn has_key_with_string_ary(v: &BTreeMap<String, Value>, key: &str) -> bool {
|
||||
v.get(key)
|
||||
.map(|t| match t {
|
||||
|
@ -187,10 +182,6 @@ impl AspectConfig {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn config(&self) -> &Value {
|
||||
&self.config
|
||||
}
|
||||
|
||||
fn is_parallel(init: &Value) -> bool {
|
||||
match init {
|
||||
&Value::Table(ref t) =>
|
||||
|
|
|
@ -39,8 +39,6 @@ impl Aspect {
|
|||
impl StoreIdAccessor for Aspect {
|
||||
fn access(&self, id: &StoreId) -> HookResult<()> {
|
||||
use crossbeam;
|
||||
use std::thread;
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
|
||||
if !accessors.iter().all(|a| match a { &HDA::StoreIdAccess(_) => true, _ => false }) {
|
||||
|
@ -56,7 +54,7 @@ impl StoreIdAccessor for Aspect {
|
|||
&HDA::StoreIdAccess(accessor) => accessor.access(id),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.map_err(|e| ()) // TODO: We're losing the error cause here
|
||||
.map_err(|_| ()) // TODO: We're losing the error cause here
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -108,8 +106,6 @@ impl MutableHookDataAccessor for Aspect {
|
|||
impl NonMutableHookDataAccessor for Aspect {
|
||||
fn access(&self, fle: &FileLockEntry) -> HookResult<()> {
|
||||
use crossbeam;
|
||||
use std::thread;
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
|
||||
if !accessors.iter().all(|a| match a { &HDA::NonMutableAccess(_) => true, _ => false }) {
|
||||
|
@ -125,7 +121,7 @@ impl NonMutableHookDataAccessor for Aspect {
|
|||
&HDA::NonMutableAccess(accessor) => accessor.access(fle),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
.map_err(|e| ()) // TODO: We're losing the error cause here
|
||||
.map_err(|_| ()) // TODO: We're losing the error cause here
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -2,9 +2,6 @@ use std::fmt::Debug;
|
|||
|
||||
use toml::Value;
|
||||
|
||||
use self::error::HookError;
|
||||
use store::FileLockEntry;
|
||||
|
||||
pub mod accessor;
|
||||
pub mod aspect;
|
||||
pub mod error;
|
||||
|
|
|
@ -31,30 +31,6 @@ fn create_file<A: AsRef<Path>>(p: A) -> ::std::io::Result<File> {
|
|||
|
||||
impl LazyFile {
|
||||
|
||||
/**
|
||||
* Create a new LazyFile instance from a Path
|
||||
*/
|
||||
pub fn new(p: PathBuf) -> LazyFile {
|
||||
LazyFile::Absent(p)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new LazyFile instance from an already existing file
|
||||
*/
|
||||
pub fn new_with_file(f: File) -> LazyFile {
|
||||
LazyFile::File(f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file behind a LazyFile object
|
||||
*/
|
||||
pub fn get_file(&mut self) -> Result<&File, StoreError> {
|
||||
match self.get_file_mut() {
|
||||
Ok(file) => Ok(&*file),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mutable file behind a LazyFile object
|
||||
*/
|
||||
|
@ -107,9 +83,8 @@ impl LazyFile {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::LazyFile;
|
||||
use std::io::{Read, Write, Seek, SeekFrom};
|
||||
use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
use tempdir::TempDir;
|
||||
|
||||
fn get_dir() -> TempDir {
|
||||
|
@ -121,7 +96,7 @@ mod test {
|
|||
let dir = get_dir();
|
||||
let mut path = PathBuf::from(dir.path());
|
||||
path.set_file_name("test1");
|
||||
let mut lf = LazyFile::new(path);
|
||||
let mut lf = LazyFile::Absent(path);
|
||||
|
||||
write!(lf.create_file().unwrap(), "Hello World").unwrap();
|
||||
dir.close().unwrap();
|
||||
|
@ -132,7 +107,7 @@ mod test {
|
|||
let dir = get_dir();
|
||||
let mut path = PathBuf::from(dir.path());
|
||||
path.set_file_name("test2");
|
||||
let mut lf = LazyFile::new(path.clone());
|
||||
let mut lf = LazyFile::Absent(path.clone());
|
||||
|
||||
{
|
||||
let mut file = lf.create_file().unwrap();
|
||||
|
@ -142,7 +117,7 @@ mod test {
|
|||
}
|
||||
|
||||
{
|
||||
let mut file = lf.get_file().unwrap();
|
||||
let mut file = lf.get_file_mut().unwrap();
|
||||
let mut s = Vec::new();
|
||||
file.read_to_end(&mut s).unwrap();
|
||||
assert_eq!(s, "Hello World".to_string().into_bytes());
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
#![deny(
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
path_statements,
|
||||
trivial_numeric_casts,
|
||||
unstable_features,
|
||||
unused_allocation,
|
||||
unused_import_braces,
|
||||
unused_imports,
|
||||
unused_mut,
|
||||
unused_qualifications,
|
||||
while_true,
|
||||
)]
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate version;
|
||||
extern crate fs2;
|
||||
|
|
|
@ -15,8 +15,6 @@ use std::ops::DerefMut;
|
|||
|
||||
use toml::{Table, Value};
|
||||
use regex::Regex;
|
||||
use crossbeam;
|
||||
use crossbeam::ScopedJoinHandle;
|
||||
use glob::glob;
|
||||
|
||||
use error::{ParserErrorKind, ParserError};
|
||||
|
@ -25,12 +23,9 @@ use storeid::{StoreId, StoreIdIterator};
|
|||
use lazyfile::LazyFile;
|
||||
|
||||
use hook::aspect::Aspect;
|
||||
use hook::result::HookResult;
|
||||
use hook::accessor::{ MutableHookDataAccessor,
|
||||
NonMutableHookDataAccessor,
|
||||
StoreIdAccessor,
|
||||
HookDataAccessor,
|
||||
HookDataAccessorProvider};
|
||||
StoreIdAccessor};
|
||||
use hook::position::HookPosition;
|
||||
use hook::Hook;
|
||||
|
||||
|
@ -81,7 +76,7 @@ impl StoreEntry {
|
|||
// TODO:
|
||||
let mut file = file.unwrap();
|
||||
let entry = Entry::from_file(self.id.clone(), &mut file);
|
||||
file.seek(SeekFrom::Start(0));
|
||||
file.seek(SeekFrom::Start(0)).ok();
|
||||
entry
|
||||
}
|
||||
} else {
|
||||
|
@ -95,10 +90,11 @@ impl StoreEntry {
|
|||
let file = try!(self.file.create_file());
|
||||
|
||||
assert_eq!(self.id, entry.location);
|
||||
file.write_all(entry.to_str().as_bytes());
|
||||
file.write_all(entry.to_str().as_bytes())
|
||||
.map_err(|e| StoreError::new(StoreErrorKind::FileError, Some(Box::new(e))))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,7 +420,7 @@ impl Store {
|
|||
debug!(" in position: {:?}", position);
|
||||
debug!(" with aspect: {:?}", aspect_name);
|
||||
|
||||
let mut guard = match position {
|
||||
let guard = match position {
|
||||
HookPosition::PreRead => self.pre_read_aspects.clone(),
|
||||
HookPosition::PostRead => self.post_read_aspects.clone(),
|
||||
HookPosition::PreCreate => self.pre_create_aspects.clone(),
|
||||
|
@ -437,7 +433,7 @@ impl Store {
|
|||
HookPosition::PostDelete => self.post_delete_aspects.clone(),
|
||||
};
|
||||
|
||||
let mut guard = guard
|
||||
let guard = guard
|
||||
.deref()
|
||||
.lock()
|
||||
.map_err(|_| StoreError::new(StoreErrorKind::HookRegisterError, None));
|
||||
|
@ -505,22 +501,6 @@ impl Store {
|
|||
.map_err(|e| StoreError::new(StoreErrorKind::PreHookExecuteError, Some(Box::new(e))))
|
||||
}
|
||||
|
||||
fn execute_hooks_for_file(&self,
|
||||
aspects: Arc<Mutex<Vec<Aspect>>>,
|
||||
fle: &FileLockEntry)
|
||||
-> Result<()>
|
||||
{
|
||||
let guard = aspects.deref().lock();
|
||||
if guard.is_err() { return Err(StoreError::new(StoreErrorKind::PreHookExecuteError, None)) }
|
||||
|
||||
guard.unwrap().deref().iter()
|
||||
.fold(Ok(()), |acc, aspect| {
|
||||
debug!("[Aspect][exec]: {:?}", aspect);
|
||||
acc.and_then(|_| (aspect as &NonMutableHookDataAccessor).access(fle))
|
||||
})
|
||||
.map_err(|e| StoreError::new(StoreErrorKind::PreHookExecuteError, Some(Box::new(e))))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Drop for Store {
|
||||
|
@ -1306,8 +1286,6 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_verification_current_version() {
|
||||
use version;
|
||||
|
||||
use super::verify_header_consistency;
|
||||
|
||||
let mut header = BTreeMap::new();
|
||||
|
|
|
@ -82,7 +82,7 @@ macro_rules! module_entry_path_mod {
|
|||
}
|
||||
|
||||
impl $crate::storeid::IntoStoreId for ModuleEntryPath {
|
||||
fn into_storeid(mut self) -> $crate::storeid::StoreId {
|
||||
fn into_storeid(self) -> $crate::storeid::StoreId {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue