repoinfo: Add info about hot repo

This commit is contained in:
Alexander Weiss 2022-07-14 08:33:43 +02:00
parent c0f2c43238
commit e8d966dc39
2 changed files with 35 additions and 22 deletions

View File

@ -166,7 +166,7 @@ pub async fn execute() -> Result<()> {
Command::Snapshots(opts) => snapshots::execute(&dbe, opts).await?,
Command::Prune(opts) => prune::execute(&dbe, opts, config, vec![]).await?,
Command::Restore(opts) => restore::execute(&dbe, opts).await?,
Command::Repoinfo(opts) => repoinfo::execute(&dbe, opts).await?,
Command::Repoinfo(opts) => repoinfo::execute(&dbe, &be_hot, opts).await?,
Command::Tag(opts) => tag::execute(&dbe, opts).await?,
};

View File

@ -5,7 +5,7 @@ use prettytable::{cell, format, row, Table};
use vlog::*;
use super::{bytes, progress_counter};
use crate::backend::{DecryptReadBackend, ALL_FILE_TYPES};
use crate::backend::{DecryptReadBackend, ReadBackend, ALL_FILE_TYPES};
use crate::blob::BlobType;
use crate::index::IndexEntry;
use crate::repo::IndexFile;
@ -13,27 +13,15 @@ use crate::repo::IndexFile;
#[derive(Parser)]
pub(super) struct Opts;
pub(super) async fn execute(be: &impl DecryptReadBackend, _opts: Opts) -> Result<()> {
v1!("scanning files...");
let mut table = Table::new();
let mut total_count = 0;
let mut total_size = 0;
for tpe in ALL_FILE_TYPES {
let list = be.list_with_size(tpe).await?;
let count = list.len();
let size = list.iter().map(|f| f.1 as u64).sum();
table.add_row(row![format!("{:?}", tpe), r->count, r->bytes(size)]);
total_count += count;
total_size += size;
pub(super) async fn execute(
be: &impl DecryptReadBackend,
hot_be: &Option<impl ReadBackend>,
_opts: Opts,
) -> Result<()> {
fileinfo("repository files", be).await?;
if let Some(hot_be) = hot_be {
fileinfo("hot repository files", hot_be).await?;
}
table.add_row(row!["Total",r->total_count,r->bytes(total_size)]);
table.set_titles(row![b->"File type", br->"Count", br->"Total Size"]);
table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
println!();
table.printstd();
println!();
v1!("scanning index...");
let p = progress_counter();
@ -105,3 +93,28 @@ pub(super) async fn execute(be: &impl DecryptReadBackend, _opts: Opts) -> Result
Ok(())
}
async fn fileinfo(text: &str, be: &impl ReadBackend) -> Result<()> {
v1!("scanning files...");
let mut table = Table::new();
let mut total_count = 0;
let mut total_size = 0;
for tpe in ALL_FILE_TYPES {
let list = be.list_with_size(tpe).await?;
let count = list.len();
let size = list.iter().map(|f| f.1 as u64).sum();
table.add_row(row![format!("{:?}", tpe), r->count, r->bytes(size)]);
total_count += count;
total_size += size;
}
println!("{}", text);
table.add_row(row!["Total",r->total_count,r->bytes(total_size)]);
table.set_titles(row![b->"File type", br->"Count", br->"Total Size"]);
table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
println!();
table.printstd();
println!();
Ok(())
}