diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-04-22 05:01:00 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-04-22 05:01:00 +0000 |
commit | 0b6adba069cd1300079c822b14832d690595cfb4 (patch) | |
tree | d5d77d43d9658e780f00c4fa27b3c7b2dad77b02 | |
parent | 5f7122928c2d21816b2d10d0b681dc6776433ccf (diff) | |
parent | d2cc05cd7a0997c16687642d9a6814a506711e41 (diff) | |
download | obnam2-0b6adba069cd1300079c822b14832d690595cfb4.tar.gz |
Merge branch 'liw/gen-size' into 'main'
show SQLite file size
Closes #29
See merge request obnam/obnam!230
-rw-r--r-- | src/cmd/show_gen.rs | 47 | ||||
-rw-r--r-- | src/generation.rs | 3 |
2 files changed, 45 insertions, 5 deletions
diff --git a/src/cmd/show_gen.rs b/src/cmd/show_gen.rs index 970a165..98c57fc 100644 --- a/src/cmd/show_gen.rs +++ b/src/cmd/show_gen.rs @@ -5,7 +5,9 @@ use crate::client::BackupClient; use crate::config::ClientConfig; use crate::error::ObnamError; use crate::fsentry::FilesystemKind; +use crate::generation::GenId; use indicatif::HumanBytes; +use serde::Serialize; use structopt::StructOpt; use tempfile::NamedTempFile; use tokio::runtime::Runtime; @@ -51,11 +53,48 @@ impl ShowGeneration { }); let total_bytes = total_bytes?; - println!("generation-id: {}", gen_id); - println!("file-count: {}", gen.file_count()?); - println!("file-bytes: {}", HumanBytes(total_bytes)); - println!("file-bytes-raw: {}", total_bytes); + let output = Output::new(gen_id) + .db_bytes(temp.path().metadata()?.len()) + .file_count(gen.file_count()?) + .file_bytes(total_bytes); + serde_json::to_writer_pretty(std::io::stdout(), &output)?; Ok(()) } } + +#[derive(Debug, Default, Serialize)] +struct Output { + generation_id: String, + file_count: u64, + file_bytes: String, + file_bytes_raw: u64, + db_bytes: String, + db_bytes_raw: u64, +} + +impl Output { + fn new(gen_id: GenId) -> Self { + Self { + generation_id: format!("{}", gen_id), + ..Self::default() + } + } + + fn file_count(mut self, n: u64) -> Self { + self.file_count = n; + self + } + + fn file_bytes(mut self, n: u64) -> Self { + self.file_bytes_raw = n; + self.file_bytes = HumanBytes(n).to_string(); + self + } + + fn db_bytes(mut self, n: u64) -> Self { + self.db_bytes_raw = n; + self.db_bytes = HumanBytes(n).to_string(); + self + } +} diff --git a/src/generation.rs b/src/generation.rs index 0a0fc77..180efbe 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -8,11 +8,12 @@ use crate::fsentry::FilesystemEntry; use crate::genmeta::{GenerationMeta, GenerationMetaError}; use crate::label::LabelChecksumKind; use crate::schema::{SchemaVersion, VersionComponent}; +use serde::Serialize; use std::fmt; use std::path::{Path, PathBuf}; /// An identifier for a generation. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub struct GenId { id: ChunkId, } |