feat: show backup sizes in list command
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/clippy Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details

export-backup
Jef Roosens 2023-07-03 12:11:41 +02:00
parent c5193f0f3c
commit bfd278abbe
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 16 additions and 1 deletions

View File

@ -20,6 +20,8 @@ use std::fs::File;
use std::io;
use std::path::{Path, PathBuf};
const BYTE_SUFFIXES: [&str; 5] = ["B", "KiB", "MiB", "GiB", "TiB"];
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum BackupType {
Full,
@ -230,11 +232,24 @@ impl<T: Clone> fmt::Display for Backup<T> {
BackupType::Incremental => 'I',
};
// Pretty-print size
// If your backup is a petabyte or larger, this will crash and you need to re-evaluate your
// life choices
let mut index = 0;
let mut size = self.size as f64;
while size >= 1024.0 {
index += 1;
size /= 1024.0;
}
write!(
f,
"{} ({}, {})",
"{} ({}, {:.2}{}, {})",
self.start_time.format(Backup::FILENAME_FORMAT),
letter,
size,
BYTE_SUFFIXES[index],
self.delta
)
}