diff --git a/src/backup/mod.rs b/src/backup/mod.rs index e1d6bfb..f569697 100644 --- a/src/backup/mod.rs +++ b/src/backup/mod.rs @@ -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 fmt::Display for Backup { 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 ) }