fs/accounting: Fix "file already closed" on transfer retries

This was caused by the recent reworking of the accounting interface.
The Transfer object was recycling the Accounting object without
resetting the stream.

See: https://forum.rclone.org/t/error-file-already-closed/11469/
See: https://forum.rclone.org/t/rclone-b2-sync-post-error-method-not-supported/11718/
This commit is contained in:
Nick Craig-Wood 2019-09-12 11:12:19 +01:00
parent e09a4ff019
commit bfbddab46b
3 changed files with 9 additions and 2 deletions

View File

@ -118,11 +118,15 @@ func (acc *Account) StopBuffering() {
// async buffer (if any) and re-adding it // async buffer (if any) and re-adding it
func (acc *Account) UpdateReader(in io.ReadCloser) { func (acc *Account) UpdateReader(in io.ReadCloser) {
acc.mu.Lock() acc.mu.Lock()
acc.StopBuffering() if acc.withBuf {
acc.StopBuffering()
}
acc.in = in acc.in = in
acc.close = in acc.close = in
acc.origIn = in acc.origIn = in
acc.WithBuffer() if acc.withBuf {
acc.WithBuffer()
}
acc.mu.Unlock() acc.mu.Unlock()
} }

View File

@ -117,6 +117,8 @@ func (tr *Transfer) Account(in io.ReadCloser) *Account {
tr.mu.Lock() tr.mu.Lock()
if tr.acc == nil { if tr.acc == nil {
tr.acc = newAccountSizeName(tr.stats, in, tr.size, tr.remote) tr.acc = newAccountSizeName(tr.stats, in, tr.size, tr.remote)
} else {
tr.acc.UpdateReader(in)
} }
tr.mu.Unlock() tr.mu.Unlock()
return tr.acc return tr.acc

View File

@ -346,6 +346,7 @@ func Copy(ctx context.Context, f fs.Fs, dst fs.Object, remote string, src fs.Obj
} else { } else {
actionTaken = "Copied (Rcat, new)" actionTaken = "Copied (Rcat, new)"
} }
// NB Rcat closes in0
dst, err = Rcat(ctx, f, remote, in0, src.ModTime(ctx)) dst, err = Rcat(ctx, f, remote, in0, src.ModTime(ctx))
newDst = dst newDst = dst
} else { } else {