diff --git a/libimaglink/src/external.rs b/libimaglink/src/external.rs index d30dec0b..97b7dce4 100644 --- a/libimaglink/src/external.rs +++ b/libimaglink/src/external.rs @@ -1,10 +1,26 @@ use libimagstore::store::EntryHeader; +use error::{LinkError, LinkErrorKind}; use link::{Link, Links}; use result::Result; -pub fn get_link(header: &EntryHeader) -> Result { - unimplemented!() +use toml::Value; +use toml::Table; + +pub fn get_link(header: &EntryHeader) -> Result> { + let uri = header.read("imag.content.uri"); + + if uri.is_err() { + let kind = LinkErrorKind::EntryHeaderReadError; + let lerr = LinkError::new(kind, Some(Box::new(uri.err().unwrap()))); + return Err(lerr); + } + let uri = uri.unwrap(); + + match uri { + Some(Value::String(s)) => Ok(Some(Link::new(s))), + _ => Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None)), + } } /// Set an external link in the header