Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

accounting: fix percentDiff calculation -- fixes #8345

Anagh Kumar Baranwal5d670fc54aa4
diff --git a/fs/accounting/stats_groups_test.go b/fs/accounting/stats_groups_test.go
index 8c02229e7..b7a817824 100644
--- a/fs/accounting/stats_groups_test.go
+++ b/fs/accounting/stats_groups_test.go
@@ -237,5 +237,14 @@ func TestCountError(t *testing.T) {
}
func percentDiff(start, end uint64) uint64 {
- return (start - end) * 100 / start
+ if start == 0 {
+ return 0 // Handle zero start value to avoid division by zero
+ }
+ var diff uint64
+ if end > start {
+ diff = end - start // Handle case where end is larger than start
+ } else {
+ diff = start - end
+ }
+ return (diff * 100) / start
}