mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
operations: fix accounting for server side copies
See: https://forum.rclone.org/t/b2-server-side-copy-doesnt-show-cumulative-progress/11154
This commit is contained in:
parent
e2b5ed6c7a
commit
50a4ed8fc4
@ -168,6 +168,28 @@ func (acc *Account) checkRead() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServerSideCopyStart should be called at the start of a server side copy
|
||||
//
|
||||
// This pretends a transfer has started
|
||||
func (acc *Account) ServerSideCopyStart() {
|
||||
acc.statmu.Lock()
|
||||
// Set start time.
|
||||
if acc.start.IsZero() {
|
||||
acc.start = time.Now()
|
||||
}
|
||||
acc.statmu.Unlock()
|
||||
}
|
||||
|
||||
// ServerSideCopyEnd accounts for a read of n bytes in a sever side copy
|
||||
func (acc *Account) ServerSideCopyEnd(n int64) {
|
||||
// Update Stats
|
||||
acc.statmu.Lock()
|
||||
acc.bytes += n
|
||||
acc.statmu.Unlock()
|
||||
|
||||
acc.stats.Bytes(n)
|
||||
}
|
||||
|
||||
// Account the read and limit bandwidth
|
||||
func (acc *Account) accountRead(n int) {
|
||||
// Update Stats
|
||||
|
@ -302,10 +302,15 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj
|
||||
if fs.Config.MaxTransfer >= 0 && accounting.Stats(ctx).GetBytes() >= int64(fs.Config.MaxTransfer) {
|
||||
return nil, accounting.ErrorMaxTransferLimitReached
|
||||
}
|
||||
in := tr.Account(nil) // account the transfer
|
||||
in.ServerSideCopyStart()
|
||||
newDst, err = doCopy(ctx, src, remote)
|
||||
if err == nil {
|
||||
dst = newDst
|
||||
accounting.Stats(ctx).Bytes(dst.Size()) // account the bytes for the server side transfer
|
||||
in.ServerSideCopyEnd(dst.Size()) // account the bytes for the server side transfer
|
||||
err = in.Close()
|
||||
} else {
|
||||
_ = in.Close()
|
||||
}
|
||||
} else {
|
||||
err = fs.ErrorCantCopy
|
||||
|
Loading…
Reference in New Issue
Block a user