Rewrite process_rw_result()

It did not cover the aspect that the passed toml `Value` object was an
Array in the first place and assumed that it is an `String` instead,
which caused the function always to return an Result::Err, which was
obviousely buggy.

This is almost a rewrite of the process_rw_result() function which takes
the additional layer (Array(String)) into account and therefor fixes
this issue.
This commit is contained in:
Matthias Beyer 2016-04-12 21:55:30 +02:00
parent 92b471bb13
commit 0cc50691b6

View file

@ -131,13 +131,32 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Vec<Link>> {
if links.is_err() {
debug!("RW action on store failed. Generating LinkError");
let lerr = LinkError::new(LinkErrorKind::EntryHeaderReadError,
Some(Box::new(links.err().unwrap())));
return Err(lerr);
}
let links = links.unwrap();
if links.iter().any(|l| match l { &Value::String(_) => true, _ => false }) {
if links.is_none() {
debug!("We got no value from the header!");
return Ok(vec![])
}
let links = links.unwrap();
let links = {
match links {
Value::Array(a) => a,
_ => {
debug!("We expected an Array for the links, but there was a non-Array!");
return Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None));
},
}
};
if !links.iter().all(|l| match l { &Value::String(_) => true, _ => false }) {
debug!("At least one of the Values which were expected in the Array of links is a non-String!");
debug!("Generating LinkError");
return Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None));
}
@ -150,6 +169,7 @@ fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Vec<Link>> {
})
.collect();
debug!("Ok, the RW action was successful, returning link vector now!");
Ok(links)
}