From 031823634a4a549e31a4e1ed6a3619a2632499e5 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Fri, 7 Jul 2023 22:55:42 +0200 Subject: [PATCH] refactor list command --- crates/rustic_core/src/repository.rs | 14 +++++++++++++ src/commands/list.rs | 30 +++++++++------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/rustic_core/src/repository.rs b/crates/rustic_core/src/repository.rs index 38718427c..8a6102a5f 100644 --- a/crates/rustic_core/src/repository.rs +++ b/crates/rustic_core/src/repository.rs @@ -37,6 +37,7 @@ use crate::{ }, crypto::aespoly1305::Key, error::{KeyFileErrorKind, RepositoryErrorKind, RusticErrorKind}, + repofile::RepoFile, repofile::{configfile::ConfigFile, keyfile::find_key_in_backend}, BlobType, DecryptFullBackend, Id, IndexBackend, IndexedBackend, NoProgressBars, Node, NodeStreamer, ProgressBars, PruneOpts, PrunePlan, RusticResult, SnapshotFile, SnapshotGroup, @@ -397,6 +398,10 @@ impl Repository { status: open, }) } + + pub fn list(&self, tpe: FileType) -> RusticResult> { + Ok(self.be.list(tpe)?.into_iter()) + } } impl Repository { @@ -550,6 +555,15 @@ impl Repository { pub fn infos_index(&self) -> RusticResult { commands::repoinfo::collect_index_infos(self) } + + pub fn stream_files( + &self, + ) -> RusticResult>> { + Ok(self + .dbe() + .stream_all::(&self.pb.progress_hidden())? + .into_iter()) + } } pub trait Indexed: Open { diff --git a/src/commands/list.rs b/src/commands/list.rs index 798c96a32..6fb068ee6 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -8,7 +8,7 @@ use abscissa_core::{Command, Runnable, Shutdown}; use anyhow::{bail, Result}; -use rustic_core::{DecryptReadBackend, FileType, IndexFile, Open, ProgressBars, ReadBackend}; +use rustic_core::{FileType, IndexFile}; /// `list` subcommand #[derive(clap::Parser, Command, Debug)] @@ -36,26 +36,14 @@ impl ListCmd { let tpe = match self.tpe.as_str() { // special treatment for listing blobs: read the index and display it "blobs" => { - repo.dbe() - .stream_all::(&config.global.progress_options.progress_hidden())? - .into_iter() - .for_each(|index| { - match index { - Ok(it) => it, - Err(err) => { - status_err!("{}", err); - RUSTIC_APP.shutdown(Shutdown::Crash); - } + for item in repo.stream_files::()? { + let (_, index) = item?; + index.packs.into_iter().for_each(|pack| { + for blob in pack.blobs { + println!("{:?} {:?}", blob.tpe, blob.id); } - .1 - .packs - .into_iter() - .for_each(|pack| { - for blob in pack.blobs { - println!("{:?} {:?}", blob.tpe, blob.id); - } - }); }); + } return Ok(()); } "index" => FileType::Index, @@ -67,9 +55,9 @@ impl ListCmd { } }; - repo.be.list(tpe)?.into_iter().for_each(|id| { + for id in repo.list(tpe)? { println!("{id:?}"); - }); + } Ok(()) }