Skip to content

Commit

Permalink
Merge pull request #735 from rustic-rs/refactor-list
Browse files Browse the repository at this point in the history
refactor list command
  • Loading branch information
aawsome committed Jul 8, 2023
2 parents 8f74282 + 0318236 commit 690261e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
14 changes: 14 additions & 0 deletions crates/rustic_core/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -397,6 +398,10 @@ impl<P, S> Repository<P, S> {
status: open,
})
}

pub fn list(&self, tpe: FileType) -> RusticResult<impl Iterator<Item = Id>> {
Ok(self.be.list(tpe)?.into_iter())
}
}

impl<P: ProgressBars, S> Repository<P, S> {
Expand Down Expand Up @@ -550,6 +555,15 @@ impl<P: ProgressBars, S: Open> Repository<P, S> {
pub fn infos_index(&self) -> RusticResult<IndexInfos> {
commands::repoinfo::collect_index_infos(self)
}

pub fn stream_files<F: RepoFile>(
&self,
) -> RusticResult<impl Iterator<Item = RusticResult<(Id, F)>>> {
Ok(self
.dbe()
.stream_all::<F>(&self.pb.progress_hidden())?
.into_iter())
}
}

pub trait Indexed: Open {
Expand Down
30 changes: 9 additions & 21 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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::<IndexFile>(&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::<IndexFile>()? {
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,
Expand All @@ -67,9 +55,9 @@ impl ListCmd {
}
};

repo.be.list(tpe)?.into_iter().for_each(|id| {
for id in repo.list(tpe)? {
println!("{id:?}");
});
}

Ok(())
}
Expand Down

0 comments on commit 690261e

Please sign in to comment.