summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-06-08 01:59:19 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-07-19 20:58:27 +0200
commitf6a7345b4a481109b0226471925f4266a7691f92 (patch)
tree089199a855c43b9997891db77279235f7634a01e
parent9ad1c8d6bdca933732228ce1359bfab769c20c4d (diff)
downloadimag-f6a7345b4a481109b0226471925f4266a7691f92.zip
imag-f6a7345b4a481109b0226471925f4266a7691f92.tar.gz
Simplify: Move header verification from Value extension to Entry type
-rw-r--r--bin/core/imag-store/src/verify.rs5
-rw-r--r--lib/core/libimagstore/src/store.rs62
2 files changed, 12 insertions, 55 deletions
diff --git a/bin/core/imag-store/src/verify.rs b/bin/core/imag-store/src/verify.rs
index 900fde0..8fa0098 100644
--- a/bin/core/imag-store/src/verify.rs
+++ b/bin/core/imag-store/src/verify.rs
@@ -23,7 +23,6 @@ use libimagrt::runtime::Runtime;
use libimagutil::warn_exit::warn_exit;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
-use libimagstore::store::Header;
/// Verify the store.
///
@@ -41,13 +40,13 @@ pub fn verify(rt: &Runtime) {
.all(|fle| {
let p = fle.get_location();
let content_len = fle.get_content().len();
- let (header, status) = if fle.get_header().verify().is_ok() {
+ let (verify, status) = if fle.verify().is_ok() {
("ok", true)
} else {
("broken", false)
};
- info!("{: >6} | {: >14} | {:?}", header, content_len, p.deref());
+ info!("{: >6} | {: >14} | {:?}", verify, content_len, p.deref());
status
});
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index 92fabc4..55e6804 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -864,7 +864,16 @@ impl Entry {
///
/// Currently, this only verifies the header. This might change in the future.
pub fn verify(&self) -> Result<()> {
- self.header.verify()
+ if !has_main_section(&self.header)? {
+ Err(SE::from_kind(SEK::MissingMainSection))
+ } else if !has_imag_version_in_main_section(&self.header)? {
+ Err(SE::from_kind(SEK::MissingVersionInfo))
+ } else if !has_only_tables(&self.header)? {
+ debug!("Could not verify that it only has tables in its base table");
+ Err(SE::from_kind(SEK::NonTableInBaseTable))
+ } else {
+ Ok(())
+ }
}
}
@@ -882,15 +891,11 @@ impl PartialEq for Entry {
/// Extension trait for top-level toml::Value::Table, will only yield correct results on the
/// top-level Value::Table, but not on intermediate tables.
pub trait Header {
- fn verify(&self) -> Result<()>;
fn parse(s: &str) -> Result<Value>;
}
impl Header for Value {
- fn verify(&self) -> Result<()> {
- }
-
fn parse(s: &str) -> Result<Value> {
use toml::de::from_str;
@@ -929,7 +934,6 @@ mod test {
use std::collections::BTreeMap;
use storeid::StoreId;
- use store::Header;
use store::has_main_section;
use store::has_imag_version_in_main_section;
@@ -979,52 +983,6 @@ mod test {
assert!(has_imag_version_in_main_section(&Value::Table(map)).is_err());
}
- #[test]
- fn test_verification_good() {
- let mut header = BTreeMap::new();
- let sub = {
- let mut sub = BTreeMap::new();
- sub.insert("version".into(), Value::String(String::from("0.0.0")));
-
- Value::Table(sub)
- };
-
- header.insert("imag".into(), sub);
-
- assert!(Value::Table(header).verify().is_ok());
- }
-
- #[test]
- fn test_verification_invalid_versionstring() {
- let mut header = BTreeMap::new();
- let sub = {
- let mut sub = BTreeMap::new();
- sub.insert("version".into(), Value::String(String::from("000")));
-
- Value::Table(sub)
- };
-
- header.insert("imag".into(), sub);
-
- assert!(!Value::Table(header).verify().is_ok());
- }
-
-
- #[test]
- fn test_verification_current_version() {
- let mut header = BTreeMap::new();
- let sub = {
- let mut sub = BTreeMap::new();
- sub.insert("version".into(), Value::String(String::from(env!("CARGO_PKG_VERSION"))));
-
- Value::Table(sub)
- };
-
- header.insert("imag".into(), sub);
-
- assert!(Value::Table(header).verify().is_ok());
- }
-
static TEST_ENTRY : &'static str = "---
[imag]
version = '0.0.3'