diff --git a/libimagstore/Cargo.toml b/libimagstore/Cargo.toml index e561d15e..7969b701 100644 --- a/libimagstore/Cargo.toml +++ b/libimagstore/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Matthias Beyer "] [dependencies] +log = "0.3.5" fs2 = "0.2.2" glob = "0.2.10" regex = "0.1.47" diff --git a/libimagstore/src/lazyfile.rs b/libimagstore/src/lazyfile.rs index 988639c5..b613ad91 100644 --- a/libimagstore/src/lazyfile.rs +++ b/libimagstore/src/lazyfile.rs @@ -9,6 +9,7 @@ use std::fs::{File, OpenOptions}; * * A lazy file is either absent, but a path to it is available, or it is present. */ +#[derive(Debug)] pub enum LazyFile { Absent(PathBuf), File(File) @@ -52,6 +53,7 @@ impl LazyFile { * Get the mutable file behind a LazyFile object */ pub fn get_file_mut(&mut self) -> Result<&mut File, StoreError> { + debug!("Getting lazy file: {:?}", self); let file = match *self { LazyFile::File(ref mut f) => return { // We seek to the beginning of the file since we expect each @@ -79,6 +81,7 @@ impl LazyFile { * Create a file out of this LazyFile object */ pub fn create_file(&mut self) -> Result<&mut File, StoreError> { + debug!("Creating lazy file: {:?}", self); let file = match *self { LazyFile::File(ref mut f) => return Ok(f), LazyFile::Absent(ref p) => { diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs index a8044b3b..b0fb2286 100644 --- a/libimagstore/src/lib.rs +++ b/libimagstore/src/lib.rs @@ -1,4 +1,5 @@ #[macro_use] extern crate version; +#[macro_use] extern crate log; extern crate fs2; extern crate glob; extern crate regex; diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 47135a6a..7757ebcd 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -104,18 +104,23 @@ impl Store { pub fn new(location: PathBuf) -> Result { use std::fs::create_dir_all; + debug!("Building new Store object"); if !location.exists() { + debug!("Creating store path"); let c = create_dir_all(location.clone()); if c.is_err() { + debug!("Failed"); return Err(StoreError::new(StoreErrorKind::StorePathCreate, Some(Box::new(c.err().unwrap())))); } } else { if location.is_file() { + debug!("Store path exists as file"); return Err(StoreError::new(StoreErrorKind::StorePathExists, None)); } } + debug!("Store building succeeded"); Ok(Store { location: location, entries: Arc::new(RwLock::new(HashMap::new())), @@ -221,6 +226,7 @@ impl Drop for Store { * TODO: Unlock them */ fn drop(&mut self) { + debug!("Dropping store"); } } @@ -407,6 +413,7 @@ impl Entry { } pub fn from_str(loc: StoreId, s: &str) -> Result { + debug!("Building entry from string"); let re = Regex::new(r"(?smx) ^---$ (?P
.*) # Header @@ -429,6 +436,7 @@ impl Entry { return Err(StoreError::new(StoreErrorKind::MalformedEntry, None)); } + debug!("Header and content found. Yay! Building Entry object now"); Ok(Entry { location: loc, header: try!(EntryHeader::parse(header.unwrap())),