diff --git a/cmd/auto-complete.go b/cmd/auto-complete.go index 9e4138b7..c15a7ccc 100644 --- a/cmd/auto-complete.go +++ b/cmd/auto-complete.go @@ -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 diff --git a/cmd/put-main.go b/cmd/put-main.go index 9e372ff3..27700e16 100644 --- a/cmd/put-main.go +++ b/cmd/put-main.go @@ -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.") + } +} diff --git a/cmd/put-url.go b/cmd/put-url.go index b52dad36..2b903b8f 100644 --- a/cmd/put-url.go +++ b/cmd/put-url.go @@ -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, })