mirror of
https://github.com/rustic-rs/rustic.git
synced 2025-10-26 11:18:51 +00:00
Merge pull request #735 from rustic-rs/refactor-list
refactor list command
This commit is contained in:
commit
690261ea95
@ -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<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> {
|
||||
@ -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 {
|
||||
|
||||
@ -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::<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,
|
||||
@ -67,9 +55,9 @@ impl ListCmd {
|
||||
}
|
||||
};
|
||||
|
||||
repo.be.list(tpe)?.into_iter().for_each(|id| {
|
||||
for id in repo.list(tpe)? {
|
||||
println!("{id:?}");
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user