From 522d73e6dfbb7a242b0c7822a275a9719bbe48e3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 25 Aug 2016 19:00:42 +0200 Subject: [PATCH] Fix libimagentrylink::{error, internal}::* for new StoreId interface --- libimagentrylink/src/error.rs | 3 ++- libimagentrylink/src/internal.rs | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 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/internal.rs b/libimagentrylink/src/internal.rs index 6032fe0b..d77599ca 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; @@ -99,9 +100,15 @@ impl InternalLinker for Entry { } fn links_into_values(links: Vec) -> Vec> { + use libimagutil::debug_result::InfoResult; + links .into_iter() - .map(|s| s.to_str().map(String::from)) + .map(|s| { + s.to_str() + .map_dbg_err(|e| format!("Failed to translate StoreId to String: {:?}", e)) + .ok() + }) .unique() .map(|elem| elem.map(Value::String)) .sorted_by(|a, b| { @@ -157,6 +164,8 @@ fn add_foreign_link(target: &mut Entry, from: StoreId) -> Result<()> { } fn process_rw_result(links: StoreResult>) -> Result> { + use std::path::PathBuf; + let links = match links { Err(e) => { debug!("RW action on store failed. Generating LinkError"); @@ -179,14 +188,15 @@ fn process_rw_result(links: StoreResult>) -> Result> { return Err(LEK::ExistingLinkTypeWrong.into()); } - let links : Vec = links.into_iter() + let links : Vec = 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)