From 9a9a13418894f4200c21943984d95c326ea6823a Mon Sep 17 00:00:00 2001 From: Ivan Andreev Date: Fri, 18 Sep 2020 17:58:44 +0300 Subject: [PATCH] Merge pull request #4608 from ivandeex/pr-chunker-crypt chunker: fix upload over crypt (fixes #4570) --- backend/chunker/chunker.go | 8 +++++++- fstest/test_all/config.yaml | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/chunker/chunker.go b/backend/chunker/chunker.go index 5bdfa7a4d..a8ee098f3 100644 --- a/backend/chunker/chunker.go +++ b/backend/chunker/chunker.go @@ -958,6 +958,8 @@ func (f *Fs) put(ctx context.Context, in io.Reader, src fs.ObjectInfo, remote st } info := f.wrapInfo(src, chunkRemote, size) + // Refill chunkLimit and let basePut repeatedly call chunkingReader.Read() + c.chunkLimit = c.chunkSize // TODO: handle range/limit options chunk, errChunk := basePut(ctx, wrapIn, info, options...) if errChunk != nil { @@ -1166,10 +1168,14 @@ func (c *chunkingReader) updateHashes() { func (c *chunkingReader) Read(buf []byte) (bytesRead int, err error) { if c.chunkLimit <= 0 { // Chunk complete - switch to next one. + // Note #1: // We might not get here because some remotes (eg. box multi-uploader) // read the specified size exactly and skip the concluding EOF Read. // Then a check in the put loop will kick in. - c.chunkLimit = c.chunkSize + // Note #2: + // The crypt backend after receiving EOF here will call Read again + // and we must insist on returning EOF, so we postpone refilling + // chunkLimit to the main loop. return 0, io.EOF } if int64(len(buf)) > c.chunkLimit { diff --git a/fstest/test_all/config.yaml b/fstest/test_all/config.yaml index 6d9cd3a63..9581d3b5e 100644 --- a/fstest/test_all/config.yaml +++ b/fstest/test_all/config.yaml @@ -71,6 +71,10 @@ backends: remote: "TestChunkerChunk50bSHA1HashS3:" fastlist: true maxfile: 1k + - backend: "chunker" + remote: "TestChunkerOverCrypt:" + fastlist: true + maxfile: 6k - backend: "chunker" remote: "TestChunkerChunk50bMD5QuickS3:" fastlist: true