Merge pull request #470 from matthiasbeyer/libimagentrylink/cleanup
Libimagentrylink/cleanup
This commit is contained in:
commit
1cc81b6d3a
2 changed files with 17 additions and 33 deletions
|
@ -45,15 +45,7 @@ impl<'a> Link<'a> {
|
|||
/// For interal use only. Load an Link from a store id, if this is actually a Link
|
||||
fn retrieve(store: &'a Store, id: StoreId) -> Result<Option<Link<'a>>> {
|
||||
store.retrieve(id)
|
||||
.map(|fle| {
|
||||
if let Some(_) = Link::get_link_uri_from_filelockentry(&fle) {
|
||||
Some(Link {
|
||||
link: fle
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|fle| Link::get_link_uri_from_filelockentry(&fle).map(|_| Link { link: fle }))
|
||||
.map_err(|e| LE::new(LEK::StoreReadError, Some(Box::new(e))))
|
||||
}
|
||||
|
||||
|
@ -62,11 +54,9 @@ impl<'a> Link<'a> {
|
|||
file.get_header()
|
||||
.read("imag.content.uri")
|
||||
.ok()
|
||||
.and_then(|opt| {
|
||||
match opt {
|
||||
Some(Value::String(s)) => Url::parse(&s[..]).ok(),
|
||||
_ => None
|
||||
}
|
||||
.and_then(|opt| match opt {
|
||||
Some(Value::String(s)) => Url::parse(&s[..]).ok(),
|
||||
_ => None
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -137,25 +137,19 @@ 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");
|
||||
return Err(LEK::EntryHeaderReadError.into_error_with_cause(Box::new(links.unwrap_err())))
|
||||
}
|
||||
let links = links.unwrap();
|
||||
|
||||
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(LEK::ExistingLinkTypeWrong.into());
|
||||
},
|
||||
let links = match links {
|
||||
Err(e) => {
|
||||
debug!("RW action on store failed. Generating LinkError");
|
||||
return Err(LEK::EntryHeaderReadError.into_error_with_cause(Box::new(e)))
|
||||
},
|
||||
Ok(None) => {
|
||||
debug!("We got no value from the header!");
|
||||
return Ok(vec![])
|
||||
},
|
||||
Ok(Some(Value::Array(l))) => l,
|
||||
Ok(Some(_)) => {
|
||||
debug!("We expected an Array for the links, but there was a non-Array!");
|
||||
return Err(LEK::ExistingLinkTypeWrong.into());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue