From 6b1fdfbc1d172337b6aeb9f45ebb5e40c918244f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 17 Jul 2016 00:36:37 +0200 Subject: Add Store::verify() --- libimagstore/Cargo.toml | 4 ++++ libimagstore/src/store.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libimagstore/Cargo.toml b/libimagstore/Cargo.toml index 050472a0..3f253a68 100644 --- a/libimagstore/Cargo.toml +++ b/libimagstore/Cargo.toml @@ -25,3 +25,7 @@ path = "../libimagutil" tempdir = "0.3.4" env_logger = "0.3" +[features] +default = [] +verify = [] + diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 9ed41d24..be05710e 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -321,6 +321,56 @@ impl Store { self.configuration.as_ref() } + /// Verify the store. + /// + /// This function is not intended to be called by normal programs but only by `imag-store`. + #[cfg(feature = "verify")] + pub fn verify(&self) -> bool { + info!("Header | Content length | Path"); + info!("-------+----------------+-----"); + + WalkDir::new(self.location.clone()) + .into_iter() + .map(|res| { + match res { + Ok(dent) => { + if dent.file_type().is_file() { + match self.get(PathBuf::from(dent.path())) { + Ok(Some(fle)) => { + let p = fle.get_location(); + let content_len = fle.get_content().len(); + let header = if fle.get_header().verify().is_ok() { + "ok" + } else { + "broken" + }; + + info!("{: >6} | {: >14} | {:?}", header, content_len, p.deref()); + }, + + Ok(None) => { + info!("{: >6} | {: >14} | {:?}", "?", "couldn't load", dent.path()); + }, + + Err(e) => { + debug!("{:?}", e); + }, + } + } else { + info!("{: >6} | {: >14} | {:?}", "?", "", dent.path()); + } + }, + + Err(e) => { + debug!("{:?}", e); + }, + } + + true + }) + .all(|b| b) + } + /// Creates the Entry at the given location (inside the entry) pub fn create<'a, S: IntoStoreId>(&'a self, id: S) -> Result> { let id = id.into_storeid().storified(self); -- cgit v1.2.3