summaryrefslogtreecommitdiffstats
path: root/libimagentrylink/src
diff options
context:
space:
mode:
Diffstat (limited to 'libimagentrylink/src')
-rw-r--r--libimagentrylink/src/error.rs3
-rw-r--r--libimagentrylink/src/external.rs12
-rw-r--r--libimagentrylink/src/internal.rs50
-rw-r--r--libimagentrylink/src/lib.rs2
4 files changed, 36 insertions, 31 deletions
diff --git a/libimagentrylink/src/error.rs b/libimagentrylink/src/error.rs
index e975ac4a..9c756c3b 100644
--- a/libimagentrylink/src/error.rs
+++ b/libimagentrylink/src/error.rs
@@ -7,7 +7,8 @@ generate_error_module!(
InternalConversionError => "Error while converting values internally",
InvalidUri => "URI is not valid",
StoreReadError => "Store read error",
- StoreWriteError => "Store write error"
+ StoreWriteError => "Store write error",
+ StoreIdError => "StoreId handling error"
);
);
diff --git a/libimagentrylink/src/external.rs b/libimagentrylink/src/external.rs
index a92b8af1..a6c2faef 100644
--- a/libimagentrylink/src/external.rs
+++ b/libimagentrylink/src/external.rs
@@ -91,8 +91,8 @@ pub trait ExternalLinker : InternalLinker {
/// Check whether the StoreId starts with `/link/external/`
pub fn is_external_link_storeid(id: &StoreId) -> bool {
- debug!("Checking whether this is a /link/external/*: '{:?}'", id);
- id.parent().map(|par| par.ends_with("/link/external")).unwrap_or(false)
+ debug!("Checking whether this is a link/external/*: '{:?}'", id);
+ id.local().starts_with("link/external")
}
fn get_external_link_from_file(entry: &FileLockEntry) -> Result<Url> {
@@ -144,7 +144,13 @@ impl ExternalLinker for Entry {
s.input_str(&link.as_str()[..]);
s.result_str()
};
- let file_id = ModuleEntryPath::new(format!("external/{}", hash)).into_storeid();
+ let file_id = try!(
+ ModuleEntryPath::new(format!("external/{}", hash)).into_storeid()
+ .map_err_into(LEK::StoreWriteError)
+ .map_dbg_err(|_| {
+ format!("Failed to build StoreId for this hash '{:?}'", hash)
+ })
+ );
debug!("Link = '{:?}'", link);
debug!("Hash = '{:?}'", hash);
diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs
index 6032fe0b..e6dddb6f 100644
--- a/libimagentrylink/src/internal.rs
+++ b/libimagentrylink/src/internal.rs
@@ -7,6 +7,7 @@ use libimagstore::store::Result as StoreResult;
use libimagerror::into::IntoError;
use error::LinkErrorKind as LEK;
+use error::MapErrInto;
use result::Result;
use toml::Value;
@@ -53,13 +54,11 @@ impl InternalLinker for Entry {
.into_iter()
.fold(Ok(vec![]), |acc, elem| {
acc.and_then(move |mut v| {
- match elem {
- None => Err(LEK::InternalConversionError.into()),
- Some(e) => {
+ elem.map_err_into(LEK::InternalConversionError)
+ .map(|e| {
v.push(e);
- Ok(v)
- },
- }
+ v
+ })
})
}));
process_rw_result(self.get_header_mut().set("imag.links", Value::Array(new_links)))
@@ -98,17 +97,17 @@ impl InternalLinker for Entry {
}
-fn links_into_values(links: Vec<StoreId>) -> Vec<Option<Value>> {
+fn links_into_values(links: Vec<StoreId>) -> Vec<Result<Value>> {
links
.into_iter()
- .map(|s| s.to_str().map(String::from))
.unique()
+ .map(|s| s.without_base().to_str().map_err_into(LEK::InternalConversionError))
.map(|elem| elem.map(Value::String))
.sorted_by(|a, b| {
match (a, b) {
- (&Some(Value::String(ref a)), &Some(Value::String(ref b))) => Ord::cmp(a, b),
- (&None, _) | (_, &None) => Ordering::Equal,
- _ => unreachable!()
+ (&Ok(Value::String(ref a)), &Ok(Value::String(ref b))) => Ord::cmp(a, b),
+ (&Err(_), _) | (_, &Err(_)) => Ordering::Equal,
+ _ => unreachable!()
}
})
}
@@ -118,13 +117,11 @@ fn rewrite_links(header: &mut EntryHeader, links: Vec<StoreId>) -> Result<()> {
.into_iter()
.fold(Ok(vec![]), |acc, elem| {
acc.and_then(move |mut v| {
- match elem {
- None => Err(LEK::InternalConversionError.into()),
- Some(e) => {
+ elem.map_err_into(LEK::InternalConversionError)
+ .map(|e| {
v.push(e);
- Ok(v)
- },
- }
+ v
+ })
})
}));
@@ -142,13 +139,11 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
.into_iter()
.fold(Ok(vec![]), |acc, elem| {
acc.and_then(move |mut v| {
- match elem {
- None => Err(LEK::InternalConversionError.into()),
- Some(e) => {
+ elem.map_err_into(LEK::InternalConversionError)
+ .map(|e| {
v.push(e);
- Ok(v)
- },
- }
+ v
+ })
})
}));
process_rw_result(target.get_header_mut().set("imag.links", Value::Array(links)))
@@ -157,6 +152,8 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> {
}
fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Vec<Link>> {
+ use std::path::PathBuf;
+
let links = match links {
Err(e) => {
debug!("RW action on store failed. Generating LinkError");
@@ -179,14 +176,15 @@ fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Vec<Link>> {
return Err(LEK::ExistingLinkTypeWrong.into());
}
- let links : Vec<Link> = links.into_iter()
+ let links : Vec<Link> = try!(links.into_iter()
.map(|link| {
match link {
- Value::String(s) => StoreId::from(s),
+ Value::String(s) => StoreId::new_baseless(PathBuf::from(s))
+ .map_err_into(LEK::StoreIdError),
_ => unreachable!(),
}
})
- .collect();
+ .collect());
debug!("Ok, the RW action was successful, returning link vector now!");
Ok(links)
diff --git a/libimagentrylink/src/lib.rs b/libimagentrylink/src/lib.rs
index 1774c8a6..804916fc 100644
--- a/libimagentrylink/src/lib.rs
+++ b/libimagentrylink/src/lib.rs
@@ -23,7 +23,7 @@ extern crate crypto;
#[macro_use] extern crate libimagerror;
#[macro_use] extern crate libimagutil;
-module_entry_path_mod!("links", "0.2.0");
+module_entry_path_mod!("links");
pub mod error;
pub mod external;