accounting: fix panic due to server-side copy fallback

This commit is contained in:
Ivan Andreev 2019-09-13 20:08:01 +03:00 committed by Nick Craig-Wood
parent 661dc568f3
commit d98d1be3fe
2 changed files with 17 additions and 0 deletions

View file

@ -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()

View file

@ -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
}