Skip to content

Commit

Permalink
feat(commands): Add list indexpacks and list indexcontent commands (#…
Browse files Browse the repository at this point in the history
…1254)

This allows better analysis of reported bugs related to the index.
  • Loading branch information
aawsome committed Sep 23, 2024
1 parent f5499db commit 5ec9652
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 37 additions & 7 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! `list` subcommand

use std::num::NonZero;

use crate::{commands::open_repository, status_err, Application, RUSTIC_APP};

use abscissa_core::{Command, Runnable, Shutdown};

use anyhow::{bail, Result};

use rustic_core::repofile::{IndexFile, IndexId, KeyId, PackId, SnapshotId};
Expand All @@ -12,7 +13,7 @@ use rustic_core::repofile::{IndexFile, IndexId, KeyId, PackId, SnapshotId};
#[derive(clap::Parser, Command, Debug)]
pub(crate) struct ListCmd {
/// File types to list
#[clap(value_parser=["blobs", "index", "packs", "snapshots", "keys"])]
#[clap(value_parser=["blobs", "indexpacks", "indexcontent", "index", "packs", "snapshots", "keys"])]
tpe: String,
}

Expand All @@ -32,14 +33,43 @@ impl ListCmd {

match self.tpe.as_str() {
// special treatment for listing blobs: read the index and display it
"blobs" => {
"blobs" | "indexpacks" | "indexcontent" => {
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);
for pack in index.packs {
match self.tpe.as_str() {
"blobs" => {
for blob in pack.blobs {
println!("{:?} {:?}", blob.tpe, blob.id);
}
}
"indexcontent" => {
for blob in pack.blobs {
println!(
"{:?} {:?} {:?} {} {}",
blob.tpe,
blob.id,
pack.id,
blob.length,
blob.uncompressed_length.map_or(0, NonZero::get)
);
}
}
"indexpacks" => println!(
"{:?} {:?} {} {}",
pack.blob_type(),
pack.id,
pack.pack_size(),
pack.time.map_or_else(String::new, |time| format!(
"{}",
time.format("%Y-%m-%d %H:%M:%S")
))
),
t => {
bail!("invalid type: {}", t);
}
}
});
}
}
}
"index" => {
Expand Down

0 comments on commit 5ec9652

Please sign in to comment.