From d977fa25fa0e0eaafeeb0bf1126dd312db51ede8 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Wed, 3 Jan 2024 20:21:08 +0800 Subject: [PATCH] ftp: fix multi-thread copy Before this change multi-thread copies using the FTP backend used to error with 551 Error reading file This was caused by a spurious error being reported which this code silences. Fixes #7532 See #3942 --- fstest/test_all/config.yaml | 4 ---- lib/readers/limited.go | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fstest/test_all/config.yaml b/fstest/test_all/config.yaml index 0e79602aa..cba00b2a6 100644 --- a/fstest/test_all/config.yaml +++ b/fstest/test_all/config.yaml @@ -298,10 +298,6 @@ backends: fastlist: false - backend: "ftp" remote: "TestFTPRclone:" - ignore: - - "TestMultithreadCopy/{size:131071_streams:2}" - - "TestMultithreadCopy/{size:131072_streams:2}" - - "TestMultithreadCopy/{size:131073_streams:2}" fastlist: false - backend: "box" remote: "TestBox:" diff --git a/lib/readers/limited.go b/lib/readers/limited.go index 218dd661a..2b346f47e 100644 --- a/lib/readers/limited.go +++ b/lib/readers/limited.go @@ -1,6 +1,10 @@ package readers -import "io" +import ( + "io" + + "github.com/rclone/rclone/fs" +) // LimitedReadCloser adds io.Closer to io.LimitedReader. Create one with NewLimitedReadCloser type LimitedReadCloser struct { @@ -8,6 +12,16 @@ type LimitedReadCloser struct { io.Closer } +// Close closes the underlying io.Closer. The error, if any, will be ignored if data is read completely +func (lrc *LimitedReadCloser) Close() error { + err := lrc.Closer.Close() + if err != nil && lrc.N == 0 { + fs.Debugf(nil, "ignoring close error because we already got all the data") + err = nil + } + return err +} + // NewLimitedReadCloser returns a LimitedReadCloser wrapping rc to // limit it to reading limit bytes. If limit < 0 then it does not // wrap rc, it just returns it.