Merge pull request #153 from matthiasbeyer/libimagstore/add-debugging-output
Libimagstore/add debugging output
This commit is contained in:
commit
959a68f1a6
4 changed files with 13 additions and 0 deletions
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||
authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.3.5"
|
||||
fs2 = "0.2.2"
|
||||
glob = "0.2.10"
|
||||
regex = "0.1.47"
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#[macro_use] extern crate version;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate fs2;
|
||||
extern crate glob;
|
||||
extern crate regex;
|
||||
|
|
|
@ -104,18 +104,23 @@ impl Store {
|
|||
pub fn new(location: PathBuf) -> Result<Store> {
|
||||
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<Entry> {
|
||||
debug!("Building entry from string");
|
||||
let re = Regex::new(r"(?smx)
|
||||
^---$
|
||||
(?P<header>.*) # 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())),
|
||||
|
|
Loading…
Reference in a new issue