1
mirror of https://github.com/rclone/rclone synced 2024-07-21 08:54:12 +02:00

accounting: fix unknown length file transfers count 3 transfers each #6213

This was caused by nested calls to NewTransfer/Done.

This fixes the problem by only incrementing transfers if the remote is
present in the transferMap which means we only increment it once.
This commit is contained in:
buda 2022-06-27 20:56:03 +04:00 committed by GitHub
parent fdd2f8e6d2
commit 517e7d9271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -714,10 +714,10 @@ func (s *StatsInfo) NewTransferRemoteSize(remote string, size int64) *Transfer {
// DoneTransferring removes a transfer from the stats
//
// if ok is true then it increments the transfers count
// if ok is true and it was in the transfermap (to avoid incrementing in case of nested calls, #6213) then it increments the transfers count
func (s *StatsInfo) DoneTransferring(remote string, ok bool) {
s.transferring.del(remote)
if ok {
existed := s.transferring.del(remote)
if ok && existed {
s.mu.Lock()
s.transfers++
s.mu.Unlock()

View File

@ -34,10 +34,13 @@ func (tm *transferMap) add(tr *Transfer) {
}
// del removes a transfer from the map by name
func (tm *transferMap) del(remote string) {
func (tm *transferMap) del(remote string) bool {
tm.mu.Lock()
_, exists := tm.items[remote]
delete(tm.items, remote)
tm.mu.Unlock()
return exists
}
// merge adds items from another map