diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-07-17 00:36:37 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-07-17 00:59:04 +0200 |
commit | 6b1fdfbc1d172337b6aeb9f45ebb5e40c918244f (patch) | |
tree | 51a55acb9c38c7363dd5ec7aeb40475e96a620ad /libimagstore/src/store.rs | |
parent | 29d10361b3b3cb679a29d0de462b65442a835af1 (diff) |
Add Store::verify()
Diffstat (limited to 'libimagstore/src/store.rs')
-rw-r--r-- | libimagstore/src/store.rs | 50 |
1 files changed, 50 insertions, 0 deletions
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} | {:?}", "?", "<no file>", 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<FileLockEntry<'a>> { let id = id.into_storeid().storified(self); |