fix: add error message to mc put (#4849)
This commit is contained in:
@@ -507,7 +507,7 @@ var completeCmds = map[string]complete.Predictor{
|
||||
"/quota/set": aliasCompleter,
|
||||
"/quota/info": aliasCompleter,
|
||||
"/quota/clear": aliasCompleter,
|
||||
"/put": aliasCompleter,
|
||||
"/put": complete.PredictOr(s3Completer, fsCompleter),
|
||||
}
|
||||
|
||||
// flagsToCompleteFlags transforms a cli.Flag to complete.Flags
|
||||
|
||||
+22
-3
@@ -20,10 +20,12 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v2/console"
|
||||
)
|
||||
|
||||
// put command flags.
|
||||
@@ -45,7 +47,7 @@ var (
|
||||
// Put command.
|
||||
var putCmd = cli.Command{
|
||||
Name: "put",
|
||||
Usage: "upload local object to s3 object storage",
|
||||
Usage: "upload an object to a bucket",
|
||||
Action: mainPut,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
@@ -54,7 +56,7 @@ var putCmd = cli.Command{
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] SOURCE [SOURCE...] TARGET
|
||||
{{.HelpName}} [FLAGS] SOURCE TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
@@ -125,7 +127,7 @@ func mainPut(cliCtx *cli.Context) error {
|
||||
|
||||
for putURLs := range preparePutURLs(ctx, opts) {
|
||||
if putURLs.Error != nil {
|
||||
printCopyURLsError(&putURLs)
|
||||
printPutURLsError(&putURLs)
|
||||
break
|
||||
}
|
||||
totalBytes += putURLs.SourceContent.Size
|
||||
@@ -150,3 +152,20 @@ func mainPut(cliCtx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printPutURLsError(putURLs *URLs) {
|
||||
// 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(putURLs.Error.ToGoError().Error(),
|
||||
" is a folder.") {
|
||||
errorIf(putURLs.Error.Trace(),
|
||||
"Folder cannot be copied. Please use `...` suffix.")
|
||||
} else {
|
||||
errorIf(putURLs.Error.Trace(),
|
||||
"Unable to upload.")
|
||||
}
|
||||
}
|
||||
|
||||
+19
-4
@@ -19,6 +19,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
@@ -32,7 +33,7 @@ func preparePutURLs(ctx context.Context, o prepareCopyURLsOpts) chan URLs {
|
||||
defer close(copyURLsCh)
|
||||
copyURLsContent, err := guessPutURLType(ctx, o)
|
||||
if err != nil {
|
||||
copyURLsCh <- URLs{Error: errUnableToGuess().Trace(o.sourceURLs...)}
|
||||
copyURLsCh <- URLs{Error: err}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -74,24 +75,38 @@ func guessPutURLType(ctx context.Context, o prepareCopyURLsOpts) (*copyURLsConte
|
||||
|
||||
if len(o.sourceURLs) == 1 { // 1 Source, 1 Target
|
||||
var err *probe.Error
|
||||
_, cc.sourceContent, err = url2Stat(ctx, url2StatOptions{urlStr: cc.sourceURL, versionID: o.versionID, fileAttr: false, encKeyDB: o.encKeyDB, timeRef: o.timeRef, isZip: o.isZip, ignoreBucketExistsCheck: false})
|
||||
var client Client
|
||||
client, cc.sourceContent, err = url2Stat(ctx, url2StatOptions{urlStr: cc.sourceURL, versionID: o.versionID, fileAttr: false, encKeyDB: o.encKeyDB, timeRef: o.timeRef, isZip: o.isZip, ignoreBucketExistsCheck: false})
|
||||
if err != nil {
|
||||
cc.copyType = copyURLsTypeInvalid
|
||||
return cc, err
|
||||
}
|
||||
_, ok := client.(*fsClient)
|
||||
if !ok {
|
||||
cc.copyType = copyURLsTypeInvalid
|
||||
return cc, probe.NewError(fmt.Errorf("Source is not local filepath."))
|
||||
}
|
||||
// If recursion is ON, it is type C.
|
||||
// If source is a folder, it is Type C.
|
||||
if cc.sourceContent.Type.IsDir() {
|
||||
cc.copyType = copyURLsTypeC
|
||||
return cc, nil
|
||||
}
|
||||
client, err := newClient(o.targetURL)
|
||||
client, err = newClient(o.targetURL)
|
||||
if err != nil {
|
||||
cc.copyType = copyURLsTypeInvalid
|
||||
return cc, err
|
||||
}
|
||||
s3clnt := client.(*S3Client)
|
||||
s3clnt, ok := client.(*S3Client)
|
||||
if !ok {
|
||||
cc.copyType = copyURLsTypeInvalid
|
||||
return cc, probe.NewError(fmt.Errorf("Target is not s3."))
|
||||
}
|
||||
bucket, path := s3clnt.url2BucketAndObject()
|
||||
if bucket == "" {
|
||||
cc.copyType = copyURLsTypeInvalid
|
||||
return cc, probe.NewError(fmt.Errorf("Bucket should not be empty."))
|
||||
}
|
||||
cc.targetContent = s3clnt.objectInfo2ClientContent(bucket, minio.ObjectInfo{
|
||||
Key: bucket,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user