From 6d7c248805b8369cb7df73faf0458b409c37285b Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 21 Jul 2019 13:16:31 +0800 Subject: [PATCH] udpate get_display_size --- src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 63a7975..520f918 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,20 +60,17 @@ pub fn print_lastline(line: &str) { pub fn get_display_size(size: i64) -> String { if size < SIZE_KB { return size.to_string(); - } - if size < SIZE_MB { + } else if size < SIZE_MB { return format!("{:.*}KB", 2, (size as f64) / 1024.); - } - if size < SIZE_GB { + } else if size < SIZE_GB { return format!("{:.*}MB", 2, (size as f64) / 1024. / 1024.); - } - if size < SIZE_PB { + } else if size < SIZE_PB { return format!("{:.*}GB", 2, (size as f64) / 1024. / 1024. / 1024.); - } - if size < SIZE_TB { + } else if size < SIZE_TB { return format!("{:.*}PB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024.); + } else { + return format!("{:.*}TB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024. / 1024.); } - return format!("{:.*}TB", 2, (size as f64) / 1024. / 1024. / 1024. / 1024. / 1024.); } pub fn run_command_and_wait(cmd: &mut Command) -> io::Result<()> {