feat: show backup sizes in list command
parent
c5193f0f3c
commit
bfd278abbe
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue