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 totalBytes counting server-side copies and moves twice

ilya lavrenovb44c24cfca20
diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go
index 36602568a..edbd627b5 100644
--- a/fs/accounting/accounting.go
+++ b/fs/accounting/accounting.go
@@ -307,9 +307,10 @@ func (acc *Account) ServerSideTransferEnd(n int64) {
// serverSideEnd accounts for non specific server-side data
func (acc *Account) serverSideEnd(n int64) {
- // Account for bytes unless we are checking
+ // Account for bytes unless we are checking. The transfer needs
+ // them as well as the stats or totalBytes counts them twice.
if !acc.checking {
- acc.stats.BytesNoNetwork(n)
+ acc.accountReadNoNetwork(n)
}
}
diff --git a/fs/accounting/accounting_test.go b/fs/accounting/accounting_test.go
index af01b0f79..29090a0a5 100644
--- a/fs/accounting/accounting_test.go
+++ b/fs/accounting/accounting_test.go
@@ -256,6 +256,35 @@ func TestAccountAccounter(t *testing.T) {
}
+func TestAccountServerSideEnd(t *testing.T) {
+ for _, test := range []struct {
+ name string
+ end func(acc *Account, n int64)
+ }{
+ {"Copy", (*Account).ServerSideCopyEnd},
+ {"Move", (*Account).ServerSideMoveEnd},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ ctx := context.Background()
+ stats := NewStats(ctx)
+ tr := stats.NewTransferRemoteSize("file", 100, nil, nil)
+ acc := tr.Account(ctx, nil)
+ acc.ServerSideTransferStart()
+ test.end(acc, 100)
+
+ bytes, size := acc.progress()
+ assert.Equal(t, int64(100), bytes)
+ assert.Equal(t, int64(100), size)
+ assert.Equal(t, int64(100), stats.GetBytes())
+ // Counted once while the transfer is still in progress
+ assert.Equal(t, int64(100), stats.calculateTransferStats().totalBytes)
+
+ tr.Done(ctx, nil)
+ assert.Equal(t, int64(100), stats.calculateTransferStats().totalBytes)
+ })
+ }
+}
+
func TestAccountMaxTransfer(t *testing.T) {
ctx := context.Background()
ci := fs.GetConfig(ctx)