Fix imga-link::main::* for new StoreId interface

This commit is contained in:
Matthias Beyer 2016-08-26 10:20:34 +02:00
parent 5462714fcc
commit 17dbb1da29

View file

@ -74,10 +74,10 @@ fn handle_internal_linking(rt: &Runtime) {
for entry in cmd.value_of("list").unwrap().split(',') { for entry in cmd.value_of("list").unwrap().split(',') {
debug!("Listing for '{}'", entry); debug!("Listing for '{}'", entry);
match get_entry_by_name(rt, entry) { match get_entry_by_name(rt, entry) {
Ok(e) => { Ok(Some(e)) => {
e.get_internal_links() e.get_internal_links()
.map(|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); println!("{: <3}: {}", i, link);
} }
}) })
@ -85,6 +85,11 @@ fn handle_internal_linking(rt: &Runtime) {
.ok(); .ok();
}, },
Ok(None) => {
warn!("Entry not found: {:?}", entry);
break;
}
Err(e) => { Err(e) => {
trace_error(&e); trace_error(&e);
break; break;
@ -148,7 +153,8 @@ fn get_from_entry<'a>(rt: &'a Runtime) -> Option<FileLockEntry<'a>> {
debug!("We couldn't get the entry from name: '{:?}'", from_name); debug!("We couldn't get the entry from name: '{:?}'", from_name);
trace_error(&e); None 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<Vec<FileLockEntry<'a>>> {
for entry in values.map(|v| get_entry_by_name(rt, v)) { for entry in values.map(|v| get_entry_by_name(rt, v)) {
match entry { match entry {
Err(e) => trace_error(&e), Err(e) => trace_error(&e),
Ok(e) => v.push(e), Ok(Some(e)) => v.push(e),
Ok(None) => warn!("Entry not found: {:?}", v),
} }
} }
v v
}) })
} }
fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<FileLockEntry<'a>, StoreError> { fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockEntry<'a>>, StoreError> {
use libimagstore::storeid::build_entry_path; use std::path::PathBuf;
build_entry_path(rt.store(), name) use libimagstore::storeid::StoreId;
.and_then(|path| rt.store().retrieve(path))
StoreId::new(Some(rt.store().path().clone()), PathBuf::from(name))
.and_then(|id| rt.store().get(id))
} }
fn handle_external_linking(rt: &Runtime) { fn handle_external_linking(rt: &Runtime) {
@ -186,6 +195,11 @@ fn handle_external_linking(rt: &Runtime) {
if entry.is_err() { if entry.is_err() {
trace_error_exit(&entry.unwrap_err(), 1); 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(); let mut entry = entry.unwrap();
if scmd.is_present("add") { if scmd.is_present("add") {