[pbs-devel] [PATCH proxmox-backup 3/4] progress: add format variants

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Nov 30 16:27:20 CET 2020


for iterating over a single group, or iterating just on the group level

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 src/backup/datastore.rs | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index 4f49d03f..20617d38 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -775,14 +775,32 @@ impl StoreProgress {
 
 impl std::fmt::Display for StoreProgress {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(
-            f,
-            "{:.2}% ({} of {} groups, {} of {} group snapshots)",
-            self.percentage() * 100.0,
-            self.done_groups,
-            self.total_groups,
-            self.done_snapshots,
-            self.group_snapshots,
-        )
+        if self.group_snapshots == 0 {
+            write!(
+                f,
+                "{:.2}% ({} of {} groups)",
+                self.percentage() * 100.0,
+                self.done_groups,
+                self.total_groups,
+            )
+        } else if self.total_groups == 1 {
+            write!(
+                f,
+                "{:.2}% ({} of {} snapshots)",
+                self.percentage() * 100.0,
+                self.done_snapshots,
+                self.group_snapshots,
+            )
+        } else {
+            write!(
+                f,
+                "{:.2}% ({} of {} groups, {} of {} group snapshots)",
+                self.percentage() * 100.0,
+                self.done_groups,
+                self.total_groups,
+                self.done_snapshots,
+                self.group_snapshots,
+            )
+        }
     }
 }
-- 
2.20.1






More information about the pbs-devel mailing list