From 63821bbe3f984d3cb20501317f9b09f9b87a2ed4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 7 Jan 2020 12:17:00 -0800 Subject: [PATCH] fix: crash in cp when cpURLs return error (#3035) --- cmd/cp-main.go | 26 ++++++++++++++++++++++---- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cmd/cp-main.go b/cmd/cp-main.go index 06745dc8..18ce3e2e 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -338,6 +338,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p close(cpURLsCh) break } + var cpURLs URLs if e := json.Unmarshal([]byte(urlScanner.Text()), &cpURLs); e != nil { errorIf(probe.NewError(e), "Unable to unmarshal %s", urlScanner.Text()) @@ -359,10 +360,27 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p go func() { totalBytes := int64(0) - for cpURLs := range prepareCopyURLs(sourceURLs, targetURL, isRecursive, encKeyDB, olderThan, newerThan) { - totalBytes += cpURLs.SourceContent.Size - pg.SetTotal(totalBytes) - + for cpURLs := range prepareCopyURLs(sourceURLs, targetURL, isRecursive, + encKeyDB, olderThan, newerThan) { + if cpURLs.Error != nil { + // Print in new line and adjust to top so that we + // don't print over the ongoing scan bar + if !globalQuiet && !globalJSON { + console.Eraseline() + } + if strings.Contains(cpURLs.Error.ToGoError().Error(), + " is a folder.") { + errorIf(cpURLs.Error.Trace(), + "Folder cannot be copied. Please use `...` suffix.") + } else { + errorIf(cpURLs.Error.Trace(), + "Unable to start copying.") + } + break + } else { + totalBytes += cpURLs.SourceContent.Size + pg.SetTotal(totalBytes) + } cpURLsCh <- cpURLs } close(cpURLsCh) diff --git a/go.mod b/go.mod index a1ba0689..851617bd 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/mattn/go-runewidth v0.0.5 // indirect github.com/minio/cli v1.22.0 github.com/minio/minio v0.0.0-20191231040613-0b7bd024fb30 - github.com/minio/minio-go/v6 v6.0.45-0.20191213193129-a5786a9c2a5b + github.com/minio/minio-go/v6 v6.0.45-0.20200107003430-a505b7da2279 github.com/minio/sha256-simd v0.1.1 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/profile v1.3.0 diff --git a/go.sum b/go.sum index e7dc1b6e..130273c3 100644 --- a/go.sum +++ b/go.sum @@ -261,8 +261,8 @@ github.com/minio/lsync v1.0.1/go.mod h1:tCFzfo0dlvdGl70IT4IAK/5Wtgb0/BrTmo/jE8pA github.com/minio/minio v0.0.0-20191231040613-0b7bd024fb30 h1:s6Bt9fdUAbQ1UFssnNgB79o6xTrTHVEk3Q96QF3qAw8= github.com/minio/minio v0.0.0-20191231040613-0b7bd024fb30/go.mod h1:4Aa1o4tNqOR8ZAR80H2UCTcIi7w6H1QqHywiKXcYimM= github.com/minio/minio-go/v6 v6.0.44/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg= -github.com/minio/minio-go/v6 v6.0.45-0.20191213193129-a5786a9c2a5b h1:mzW6HUPIw2tUQsUx7x4z4RPWABWFKnI6j47DIZNl53A= -github.com/minio/minio-go/v6 v6.0.45-0.20191213193129-a5786a9c2a5b/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg= +github.com/minio/minio-go/v6 v6.0.45-0.20200107003430-a505b7da2279 h1:QJEZTaHQKwJbImgZKN12fwk41Gh75xZk+9Y4vGFRSf0= +github.com/minio/minio-go/v6 v6.0.45-0.20200107003430-a505b7da2279/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg= github.com/minio/parquet-go v0.0.0-20191231003236-20b3c07bcd2c h1:PXr/55MEoFh0G6NeV0plWrdpTDr5xaDTxP3SpavSdGc= github.com/minio/parquet-go v0.0.0-20191231003236-20b3c07bcd2c/go.mod h1:sl82d+TnCE7qeaNJazHdNoG9Gpyl9SZYfleDAQWrsls= github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=