From 8e1573ec1b9c174e9f8d82ee9996d002c1d9caaa Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Tue, 19 Dec 2023 23:14:22 -0800 Subject: [PATCH] Set exitcode on copy/mirror source failure (#4798) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also fixes errors potentially being swallowed by filtering. Fixes #4773 ``` λ go build&&mc cp s3/default/1.mp4 1.mp4 mc: Unable to prepare URL for copying. Unable to guess the type of copy operation. λ echo %errorlevel% 1 λ _ ``` --- cmd/cp-main.go | 5 +++++ cmd/cp-url.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/cmd/cp-main.go b/cmd/cp-main.go index ee6304eb..cd50c186 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -659,6 +659,11 @@ loop: } } + // Source has error + if errSeen && totalObjects == 0 && retErr == nil { + retErr = exitStatus(globalErrorExitStatus) + } + return retErr } diff --git a/cmd/cp-url.go b/cmd/cp-url.go index cdf363c3..9e3325db 100644 --- a/cmd/cp-url.go +++ b/cmd/cp-url.go @@ -361,6 +361,10 @@ func prepareCopyURLs(ctx context.Context, o prepareCopyURLsOpts) chan URLs { go func() { defer close(finalCopyURLsCh) for cpURLs := range copyURLsCh { + if cpURLs.Error != nil { + finalCopyURLsCh <- cpURLs + continue + } // Skip objects older than --older-than parameter if specified if o.olderThan != "" && isOlder(cpURLs.SourceContent.Time, o.olderThan) { continue