Merge pull request #185 from TheNeikos/verify-toml_before_write

Verify toml before write
This commit is contained in:
Matthias Beyer 2016-02-06 19:06:02 +01:00
commit ece70d78a7

View file

@ -186,6 +186,8 @@ impl Store {
assert!(se.is_borrowed(), "Tried to update a non borrowed entry."); assert!(se.is_borrowed(), "Tried to update a non borrowed entry.");
try!(entry.entry.verify());
try!(se.write_entry(&entry.entry)); try!(se.write_entry(&entry.entry));
se.status = StoreEntryStatus::Present; se.status = StoreEntryStatus::Present;
@ -320,8 +322,18 @@ impl EntryHeader {
let mut parser = Parser::new(s); let mut parser = Parser::new(s);
parser.parse() parser.parse()
.ok_or(ParserError::new(ParserErrorKind::TOMLParserErrors, None)) .ok_or(ParserError::new(ParserErrorKind::TOMLParserErrors, None))
.and_then(|t| verify_header_consistency(t)) .and_then(verify_header_consistency)
.map(|t| EntryHeader::from_table(t)) .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(())
}
} }
} }
@ -470,6 +482,10 @@ impl Entry {
&mut self.content &mut self.content
} }
pub fn verify(&self) -> Result<()> {
self.header.verify()
}
} }