From 868c585219b3b710b73d5f1d21c7b396c3f7ada1 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 19 Dec 2019 07:09:39 +0100 Subject: [PATCH] src/backup/datastore.rs: avoid divide by zero --- src/backup/datastore.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 9a60eba1..98db5772 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -269,11 +269,18 @@ impl DataStore { worker.log(&format!("Removed bytes: {}", gc_status.removed_bytes)); worker.log(&format!("Removed chunks: {}", gc_status.removed_chunks)); worker.log(&format!("Original data bytes: {}", gc_status.index_data_bytes)); - let comp_per = (gc_status.disk_bytes*100)/gc_status.index_data_bytes; - worker.log(&format!("Disk bytes: {} ({} %)", gc_status.disk_bytes, comp_per)); + + if gc_status.index_data_bytes > 0 { + let comp_per = (gc_status.disk_bytes*100)/gc_status.index_data_bytes; + worker.log(&format!("Disk bytes: {} ({} %)", gc_status.disk_bytes, comp_per)); + } + worker.log(&format!("Disk chunks: {}", gc_status.disk_chunks)); - let avg_chunk = gc_status.disk_bytes/(gc_status.disk_chunks as u64); - worker.log(&format!("Average chunk size: {}", avg_chunk)); + + if gc_status.disk_chunks > 0 { + let avg_chunk = gc_status.disk_bytes/(gc_status.disk_chunks as u64); + worker.log(&format!("Average chunk size: {}", avg_chunk)); + } *self.last_gc_status.lock().unwrap() = gc_status;