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: update String method output format for clarity in transfer rate representation - fixes #9129

Prakhar Chhalotre9601dbce87d4
diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go
index d1110c32f..5e5a3138b 100644
--- a/fs/accounting/accounting.go
+++ b/fs/accounting/accounting.go
@@ -575,8 +575,11 @@ func (acc *Account) String() string {
}
}
+ var displaySpeedString string
if acc.ci.DataRateUnit == "bits" {
- cur *= 8
+ displaySpeedString = fs.SizeSuffix(cur * 8).BitRateUnit()
+ } else {
+ displaySpeedString = fs.SizeSuffix(cur).ByteRateUnit()
}
percentageDone := 0
@@ -584,12 +587,12 @@ func (acc *Account) String() string {
percentageDone = int(100 * float64(a) / float64(b))
}
- return fmt.Sprintf("%*s:%3d%% /%s, %s/s, %s",
+ return fmt.Sprintf("%*s:%3d%% / %s, %s, %s",
acc.ci.StatsFileNameLength,
shortenName(acc.name, acc.ci.StatsFileNameLength),
percentageDone,
- fs.SizeSuffix(b),
- fs.SizeSuffix(cur),
+ fs.SizeSuffix(b).ByteUnit(),
+ displaySpeedString,
etas,
)
}
diff --git a/fs/accounting/accounting_test.go b/fs/accounting/accounting_test.go
index 02dc0f1a4..1ed1ba48a 100644
--- a/fs/accounting/accounting_test.go
+++ b/fs/accounting/accounting_test.go
@@ -183,14 +183,14 @@ func TestAccountString(t *testing.T) {
// FIXME not an exhaustive test!
- assert.Equal(t, "test: 0% /3, 0/s, -", strings.TrimSpace(acc.String()))
+ assert.Equal(t, "test: 0% / 3 B, 0 B/s, -", strings.TrimSpace(acc.String()))
var buf = make([]byte, 2)
n, err := acc.Read(buf)
assert.NoError(t, err)
assert.Equal(t, 2, n)
- assert.Equal(t, "test: 66% /3, 0/s, -", strings.TrimSpace(acc.String()))
+ assert.Equal(t, "test: 66% / 3 B, 0 B/s, -", strings.TrimSpace(acc.String()))
assert.NoError(t, acc.Close())
}