summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-07-17 00:36:37 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-07-17 00:59:04 +0200
commit6b1fdfbc1d172337b6aeb9f45ebb5e40c918244f (patch)
tree51a55acb9c38c7363dd5ec7aeb40475e96a620ad
parent29d10361b3b3cb679a29d0de462b65442a835af1 (diff)
Add Store::verify()
-rw-r--r--libimagstore/Cargo.toml4
-rw-r--r--libimagstore/src/store.rs50
2 files changed, 54 insertions, 0 deletions
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} | {:?}", "?", "<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);