From e0796283979c0263f65b9f003f2a96a90a7f64dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 6 Feb 2016 18:32:29 +0100 Subject: [PATCH 1/2] Remove unneeded closure --- libimagstore/src/store.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 16ccba60..c43abd9b 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -320,8 +320,8 @@ impl EntryHeader { let mut parser = Parser::new(s); parser.parse() .ok_or(ParserError::new(ParserErrorKind::TOMLParserErrors, None)) - .and_then(|t| verify_header_consistency(t)) - .map(|t| EntryHeader::from_table(t)) + .and_then(verify_header_consistency) + .map(EntryHeader::from_table) } } From 293fd0da0039fe7668b4a5427bee0b0b309eabc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 6 Feb 2016 18:50:39 +0100 Subject: [PATCH 2/2] Add verify --- libimagstore/src/store.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index c43abd9b..fae9094a 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -186,6 +186,8 @@ impl Store { assert!(se.is_borrowed(), "Tried to update a non borrowed entry."); + try!(entry.entry.verify()); + try!(se.write_entry(&entry.entry)); se.status = StoreEntryStatus::Present; @@ -324,6 +326,16 @@ impl EntryHeader { .map(EntryHeader::from_table) } + pub fn verify(&self) -> Result<()> { + if !has_main_section(&self.toml) { + Err(StoreError::from(ParserError::new(ParserErrorKind::MissingMainSection, None))) + } else if !has_imag_version_in_main_section(&self.toml) { + Err(StoreError::from(ParserError::new(ParserErrorKind::MissingVersionInfo, None))) + } else { + Ok(()) + } + } + } fn build_default_header() -> BTreeMap { @@ -470,6 +482,10 @@ impl Entry { &mut self.content } + pub fn verify(&self) -> Result<()> { + self.header.verify() + } + }