From 17dbb1da298f20b14abf30a13f3745e2f0a64a82 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 26 Aug 2016 10:20:34 +0200 Subject: [PATCH] Fix imga-link::main::* for new StoreId interface --- imag-link/src/main.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index c1448678..a43fb087 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -74,10 +74,10 @@ fn handle_internal_linking(rt: &Runtime) { for entry in cmd.value_of("list").unwrap().split(',') { debug!("Listing for '{}'", entry); match get_entry_by_name(rt, entry) { - Ok(e) => { + Ok(Some(e)) => { e.get_internal_links() .map(|links| { - for (i, link) in links.iter().map(|l| l.to_str()).filter_map(|x| x).enumerate() { + for (i, link) in links.iter().map(|l| l.to_str().ok()).filter_map(|x| x).enumerate() { println!("{: <3}: {}", i, link); } }) @@ -85,6 +85,11 @@ fn handle_internal_linking(rt: &Runtime) { .ok(); }, + Ok(None) => { + warn!("Entry not found: {:?}", entry); + break; + } + Err(e) => { trace_error(&e); break; @@ -148,7 +153,8 @@ fn get_from_entry<'a>(rt: &'a Runtime) -> Option> { debug!("We couldn't get the entry from name: '{:?}'", from_name); trace_error(&e); None }, - Ok(e) => Some(e), + Ok(Some(e)) => Some(e), + Ok(None) => None, } }) @@ -166,17 +172,20 @@ fn get_to_entries<'a>(rt: &'a Runtime) -> Option>> { for entry in values.map(|v| get_entry_by_name(rt, v)) { match entry { Err(e) => trace_error(&e), - Ok(e) => v.push(e), + Ok(Some(e)) => v.push(e), + Ok(None) => warn!("Entry not found: {:?}", v), } } v }) } -fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result, StoreError> { - use libimagstore::storeid::build_entry_path; - build_entry_path(rt.store(), name) - .and_then(|path| rt.store().retrieve(path)) +fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result>, StoreError> { + use std::path::PathBuf; + use libimagstore::storeid::StoreId; + + StoreId::new(Some(rt.store().path().clone()), PathBuf::from(name)) + .and_then(|id| rt.store().get(id)) } fn handle_external_linking(rt: &Runtime) { @@ -186,6 +195,11 @@ fn handle_external_linking(rt: &Runtime) { if entry.is_err() { trace_error_exit(&entry.unwrap_err(), 1); } + let entry = entry.unwrap(); + if entry.is_none() { + warn!("Entry nt found: {:?}", entry_name); + return; + } let mut entry = entry.unwrap(); if scmd.is_present("add") {