From 8f47b6746d0b81bb597ad330cb700559f1674fbc Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 24 Nov 2023 14:30:46 +0000 Subject: [PATCH] b2: fix streaming chunked files an exact multiple of chunk size Before this change, streaming files an exact multiple of the chunk size would cause rclone to attempt to stream a 0 sized chunk which was rejected by the b2 servers. This bug was noticed by the new integration tests for chunked streaming. --- backend/b2/upload.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/b2/upload.go b/backend/b2/upload.go index ef0102347..777852b1a 100644 --- a/backend/b2/upload.go +++ b/backend/b2/upload.go @@ -417,7 +417,13 @@ func (up *largeUpload) Stream(ctx context.Context, initialUploadBlock *pool.RW) } else { n, err = io.CopyN(rw, up.in, up.chunkSize) if err == io.EOF { - fs.Debugf(up.o, "Read less than a full chunk, making this the last one.") + if n == 0 { + fs.Debugf(up.o, "Not sending empty chunk after EOF - ending.") + up.f.putRW(rw) + break + } else { + fs.Debugf(up.o, "Read less than a full chunk %d, making this the last one.", n) + } hasMoreParts = false } else if err != nil { // other kinds of errors indicate failure