From d99d38bf8e963942280bc376399bcc1eec4468e3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 24 Feb 2016 13:45:37 +0100 Subject: [PATCH] Implement entry loading --- imag-view/src/main.rs | 37 ++++++++++++++++++++++++++++++++++--- imag-view/src/viewer/mod.rs | 7 +++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/imag-view/src/main.rs b/imag-view/src/main.rs index 4692337e..137d57b6 100644 --- a/imag-view/src/main.rs +++ b/imag-view/src/main.rs @@ -15,7 +15,9 @@ use clap::ArgMatches; use libimagrt::runtime::Runtime; use libimagstore::store::Entry; +use libimagstore::store::FileLockEntry; use libimagstore::store::Result as StoreResult; +use libimagstore::storeid::StoreId; use libimagutil::trace::trace_error; mod ui; @@ -69,7 +71,7 @@ fn main() { let scmd = scmd.unwrap(); let viewer = build_viewer(scmd); - let entry = load_entry(entry_id, entry_version); + let entry = load_entry(entry_id, entry_version, &rt); if entry.is_err() { trace_error(&entry.err().unwrap()); exit(1); @@ -88,8 +90,37 @@ fn main() { } } -fn load_entry(id: &str, version: Option<&str>) -> StoreResult { - unimplemented!() +// TODO: This is a shameless adaption of imag-store/src/util.rs +fn load_entry<'a>(id: &str, + version: Option<&str>, + rt: &'a Runtime) + -> StoreResult> +{ + use std::ops::Deref; + + debug!("Checking path element for version"); + + let version = { + version.unwrap_or_else(|| { + id.split("~").last().unwrap_or_else(|| { + warn!("No version"); + exit(1); + }) + }) + }; + + debug!("Building path from {:?} and {:?}", id, version); + let mut path = rt.store().path().clone(); + + if id.chars().next() == Some('/') { + path.push(format!("{}~{}", &id[1..id.len()], version)); + } else { + path.push(format!("{}~{}", id, version)); + } + + // the above is the adaption... + + rt.store().retrieve(path) } fn view_versions_of(id: &str, rt: &Runtime) { diff --git a/imag-view/src/viewer/mod.rs b/imag-view/src/viewer/mod.rs index a12d1b36..f7e3653f 100644 --- a/imag-view/src/viewer/mod.rs +++ b/imag-view/src/viewer/mod.rs @@ -1,10 +1,9 @@ pub mod stdout; -use libimagstore::store::Entry; +use libimagstore::store::FileLockEntry; -#[derive(Debug)] -pub struct ViewInformation { - pub entry: Entry, +pub struct ViewInformation<'a> { + pub entry: FileLockEntry<'a>, pub view_header: bool, pub view_content: bool, pub view_copy: bool,