"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
accounting: fix stats to show server side transfers
Nick Craig-Woodd392f9fcd8e1
diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.goindex 29681b604..41eb71225 100644--- a/fs/accounting/accounting.go+++ b/fs/accounting/accounting.go@@ -49,17 +49,18 @@ type Account struct {// in http transport calls Read() after Do() returns on// CancelRequest so this race can happen when it apparently// shouldn't.- mu sync.Mutex // mutex protects these values- in io.Reader- ctx context.Context // current context for transfer - may change- ci *fs.ConfigInfo- origIn io.ReadCloser- close io.Closer- size int64- name string- closed bool // set if the file is closed- exit chan struct{} // channel that will be closed when transfer is finished- withBuf bool // is using a buffered in+ mu sync.Mutex // mutex protects these values+ in io.Reader+ ctx context.Context // current context for transfer - may change+ ci *fs.ConfigInfo+ origIn io.ReadCloser+ close io.Closer+ size int64+ name string+ closed bool // set if the file is closed+ exit chan struct{} // channel that will be closed when transfer is finished+ withBuf bool // is using a buffered in+ checking bool // set if attached transfer is checkingtokenBucket buckets // per file bandwidth limiter (may be nil)@@ -295,14 +296,24 @@ func (acc *Account) ServerSideTransferEnd(n int64) {acc.stats.Bytes(n)}+// serverSideEnd accounts for non specific server side data+func (acc *Account) serverSideEnd(n int64) {+ // Account for bytes unless we are checking+ if !acc.checking {+ acc.stats.BytesNoNetwork(n)+ }+}+// ServerSideCopyEnd accounts for a read of n bytes in a sever side copyfunc (acc *Account) ServerSideCopyEnd(n int64) {acc.stats.AddServerSideCopy(n)+ acc.serverSideEnd(n)}// ServerSideMoveEnd accounts for a read of n bytes in a sever side movefunc (acc *Account) ServerSideMoveEnd(n int64) {acc.stats.AddServerSideMove(n)+ acc.serverSideEnd(n)}// DryRun accounts for statistics without running the operationdiff --git a/fs/accounting/stats.go b/fs/accounting/stats.goindex 24c9bcda1..665f03451 100644--- a/fs/accounting/stats.go+++ b/fs/accounting/stats.go@@ -527,6 +527,13 @@ func (s *StatsInfo) Bytes(bytes int64) {s.bytes += bytes}+// BytesNoNetwork updates the stats for bytes bytes but doesn't include the transfer stats+func (s *StatsInfo) BytesNoNetwork(bytes int64) {+ s.mu.Lock()+ defer s.mu.Unlock()+ s.bytes += bytes+}+// GetBytes returns the number of bytes transferred so farfunc (s *StatsInfo) GetBytes() int64 {s.mu.RLock()diff --git a/fs/accounting/transfer.go b/fs/accounting/transfer.goindex d4515e201..5860eefb2 100644--- a/fs/accounting/transfer.go+++ b/fs/accounting/transfer.go@@ -149,6 +149,7 @@ func (tr *Transfer) Account(ctx context.Context, in io.ReadCloser) *Account {} else {tr.acc.UpdateReader(ctx, in)}+ tr.acc.checking = tr.checkingtr.mu.Unlock()return tr.acc}