From 54484a6ee7a9ac05429cab9ba4c2af38657c3541 Mon Sep 17 00:00:00 2001 From: Matthias Beyer <mail@beyermatthias.de> Date: Tue, 20 Jun 2017 20:31:40 +0200 Subject: [PATCH 1/5] Add debug output to StoreId::new_baseless() --- libimagstore/src/storeid.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 8f63d66d..59868d95 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -67,6 +67,7 @@ impl StoreId { } pub fn new_baseless(id: PathBuf) -> Result<StoreId> { + debug!("Trying to get a new baseless id from: {:?}", id); if id.is_absolute() { Err(SEK::StoreIdLocalPartAbsoluteError.into_error()) } else { From cac3e6114ebf9c0fdd9cf065693d2c1ffc09c5bd Mon Sep 17 00:00:00 2001 From: Matthias Beyer <mail@beyermatthias.de> Date: Tue, 20 Jun 2017 20:32:03 +0200 Subject: [PATCH 2/5] Add debug output to Walk::next() impl --- libimagstore/src/store.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 52691cfb..c162b97a 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -105,21 +105,26 @@ impl Iterator for Walk { type Item = StoreObject; fn next(&mut self) -> Option<Self::Item> { + while let Some(something) = self.dirwalker.next() { + debug!("[Walk] Processing next item: {:?}", something); match something { Ok(next) => if next.file_type().is_dir() { - return Some(StoreObject::Collection(next.path().to_path_buf())) - } else if next.file_type().is_file() { - let n = next.path().to_path_buf(); - let sid = match StoreId::new(Some(self.store_path.clone()), n) { - Err(e) => { - trace_error(&e); - continue; - }, - Ok(o) => o, - }; - return Some(StoreObject::Id(sid)) - }, + debug!("Found directory..."); + return Some(StoreObject::Collection(next.path().to_path_buf())) + } else /* if next.file_type().is_file() */ { + debug!("Found file..."); + let n = next.path().to_path_buf(); + let sid = match StoreId::new(Some(self.store_path.clone()), n) { + Err(e) => { + debug!("Could not construct StoreId object from it"); + trace_error(&e); + continue; + }, + Ok(o) => o, + }; + return Some(StoreObject::Id(sid)) + }, Err(e) => { warn!("Error in Walker"); debug!("{:?}", e); From de3b244a62b95e0cc8d1c941c38dd2d387ebc0d8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer <mail@beyermatthias.de> Date: Tue, 20 Jun 2017 20:32:22 +0200 Subject: [PATCH 3/5] Bugfix: Use StoreId::from_full_path() The rationale is that the walker implementation yields the complete path rather than the local part. This patch fixes this issue by using StoreId::from_full_path() rather than StoreId::new(). --- libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index c162b97a..58b7c49b 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -115,7 +115,7 @@ impl Iterator for Walk { } else /* if next.file_type().is_file() */ { debug!("Found file..."); let n = next.path().to_path_buf(); - let sid = match StoreId::new(Some(self.store_path.clone()), n) { + let sid = match StoreId::from_full_path(&self.store_path, n) { Err(e) => { debug!("Could not construct StoreId object from it"); trace_error(&e); From e7e3a7592402cce8ca71e0382855430cf5c418a7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer <mail@beyermatthias.de> Date: Tue, 20 Jun 2017 20:42:01 +0200 Subject: [PATCH 4/5] Add another JSON test for an empty JSON --- .../src/file_abstraction/stdio/mapper/json.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libimagstore/src/file_abstraction/stdio/mapper/json.rs b/libimagstore/src/file_abstraction/stdio/mapper/json.rs index b3772b85..a153df08 100644 --- a/libimagstore/src/file_abstraction/stdio/mapper/json.rs +++ b/libimagstore/src/file_abstraction/stdio/mapper/json.rs @@ -153,6 +153,18 @@ mod test { use super::*; + #[test] + fn test_empty_json_to_fs() { + let json = r#"{"version":"0.3.0","store":{}}"#; + let mut json = Cursor::new(String::from(json).into_bytes()); + let mapper = JsonMapper::new(); + let mut hm = HashMap::new(); + + let io_res = mapper.read_to_fs(&mut json, &mut hm); + assert!(io_res.is_ok()); + assert!(hm.is_empty()); + } + #[test] fn test_json_to_fs() { let json = r#" From 14f261a84e47e8d51f84d688f956000f9dc166d0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer <mail@beyermatthias.de> Date: Tue, 20 Jun 2017 20:51:56 +0200 Subject: [PATCH 5/5] Add some debug output to JSON mapper --- .../src/file_abstraction/stdio/mapper/json.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/file_abstraction/stdio/mapper/json.rs b/libimagstore/src/file_abstraction/stdio/mapper/json.rs index a153df08..74d9e6eb 100644 --- a/libimagstore/src/file_abstraction/stdio/mapper/json.rs +++ b/libimagstore/src/file_abstraction/stdio/mapper/json.rs @@ -33,7 +33,7 @@ use storeid::StoreId; use libimagerror::into::IntoError; -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] struct BackendEntry { header: serde_json::Value, content: String, @@ -53,7 +53,7 @@ impl BackendEntry { } -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] struct Document { version: String, store: HashMap<PathBuf, BackendEntry>, @@ -72,9 +72,13 @@ impl JsonMapper { impl Mapper for JsonMapper { fn read_to_fs<R: Read>(&self, r: &mut R, hm: &mut HashMap<PathBuf, Entry>) -> Result<()> { let mut document = { + debug!("Reading Document"); let mut s = String::new(); try!(r.read_to_string(&mut s).map_err_into(SEK::IoError)); + debug!("Document = {:?}", s); + debug!("Parsing Document"); let doc : Document = try!(serde_json::from_str(&s).map_err_into(SEK::IoError)); + debug!("Document = {:?}", doc); doc }; @@ -84,6 +88,10 @@ impl Mapper for JsonMapper { // safe because cargo does not compile if crate version is not valid let crate_version = ::semver::Version::parse(version!()).unwrap(); + debug!("Document version vs. own version: {doc_vers} > {crate_vers}", + doc_vers = doc_vers, + crate_vers = crate_version); + if doc_vers > crate_version { Err(SEK::VersionError.into_error()) } else { @@ -92,9 +100,11 @@ impl Mapper for JsonMapper { })); for (key, val) in document.store.drain() { + debug!("(key, value) ({:?}, {:?})", key, val); let res = val .to_string() .and_then(|vals| { + debug!("value string = {:?}", vals); StoreId::new_baseless(key.clone()) .and_then(|id| Entry::from_str(id, &vals)) .map(|entry| hm.insert(key, entry))