From 403965d912cf1b95b3a08547b016eac52dcdd277 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Jun 2017 20:00:47 +0200 Subject: [PATCH] Implement dumping --- imag-store/src/dump.rs | 30 +++++++++++++++++++++++++++- imag-store/src/main.rs | 44 +++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/imag-store/src/dump.rs b/imag-store/src/dump.rs index 9463c46a..2c904127 100644 --- a/imag-store/src/dump.rs +++ b/imag-store/src/dump.rs @@ -17,7 +17,35 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +use std::process::exit; + +use libimagrt::runtime::Runtime; +use libimagerror::trace::*; + pub fn dump(rt: &mut Runtime) { - unimplemented!() + let cachingres = rt + .store() + .entries() + .map_err_trace() + .map(|iter| { + for elem in iter { + debug!("Working on {:?}", elem); + if let Ok(_) = rt.store().get(elem.clone()).map_err_dbg_trace() { + info!("Loading entry at {:?} succeeded", elem); + } else { + error!("Loading entry at {:?} failed", elem); + } + } + }); + + if let Ok(_) = cachingres { + if let Err(_) = rt.store_backend_to_stdio().map_err_trace() { + error!("Loading Store IO backend failed"); + exit(1); + } + } else { + error!("Loading entries failed"); + exit(1); + } } diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs index d2ddc464..c425bf7b 100644 --- a/imag-store/src/main.rs +++ b/imag-store/src/main.rs @@ -47,6 +47,7 @@ use libimagrt::setup::generate_runtime_setup; mod create; mod delete; +mod dump; mod error; mod get; mod retrieve; @@ -55,8 +56,11 @@ mod update; mod verify; mod util; +use std::ops::Deref; + use create::create; use delete::delete; +use dump::dump; use get::get; use retrieve::retrieve; use ui::build_ui; @@ -69,29 +73,25 @@ fn main() { "Direct interface to the store. Use with great care!", build_ui); - rt.cli() - .subcommand_name() - .map_or_else( - || { - debug!("No command"); + let command = rt.cli().subcommand_name().map(String::from); + + if let Some(command) = command { + debug!("Call: {}", command); + match command.deref() { + "create" => create(&rt), + "delete" => delete(&rt), + "get" => get(&rt), + "retrieve" => retrieve(&rt), + "update" => update(&rt), + "verify" => verify(&rt), + "dump" => dump(&mut rt), + _ => { + debug!("Unknown command"); // More error handling }, - |name| { - debug!("Call: {}", name); - match name { - "create" => create(&rt), - "delete" => delete(&rt), - "get" => get(&rt), - "retrieve" => retrieve(&rt), - "update" => update(&rt), - "verify" => verify(&rt), - "dump" => dump(&mut rt), - _ => { - debug!("Unknown command"); - // More error handling - }, - }; - } - ) + }; + } else { + debug!("No command"); + } }