diff --git a/fs/accounting/transfer.go b/fs/accounting/transfer.go index dc5e90d0e..a7015b918 100644 --- a/fs/accounting/transfer.go +++ b/fs/accounting/transfer.go @@ -115,6 +115,20 @@ func (tr *Transfer) Done(err error) { } } +// Reset allows to switch the Account to another transfer method. +func (tr *Transfer) Reset() { + tr.mu.RLock() + acc := tr.acc + tr.acc = nil + tr.mu.RUnlock() + + if acc != nil { + if err := acc.Close(); err != nil { + fs.LogLevelPrintf(fs.Config.StatsLogLevel, nil, "can't close account: %+v\n", err) + } + } +} + // Account returns reader that knows how to keep track of transfer progress. func (tr *Transfer) Account(in io.ReadCloser) *Account { tr.mu.Lock() diff --git a/fs/operations/operations.go b/fs/operations/operations.go index dbc626dfc..30ba3cd50 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -312,6 +312,9 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj } else { _ = in.Close() } + if err == fs.ErrorCantCopy { + tr.Reset() // skip incomplete accounting - will be overwritten by the manual copy below + } } else { err = fs.ErrorCantCopy }