Add verify
This commit is contained in:
parent
e079628397
commit
293fd0da00
1 changed files with 16 additions and 0 deletions
|
@ -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<String, Value> {
|
||||
|
@ -470,6 +482,10 @@ impl Entry {
|
|||
&mut self.content
|
||||
}
|
||||
|
||||
pub fn verify(&self) -> Result<()> {
|
||||
self.header.verify()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue