From af7d43dfe6faba48858c8d48aef51765b99b356a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 16 May 2015 02:16:13 -0700 Subject: [PATCH] Some cleanup, sync to be enabled --- cmd-copy.go | 10 +++------- cmd-sync.go | 18 ++++++++---------- copy-url.go | 8 +++----- errors.go | 2 +- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/cmd-copy.go b/cmd-copy.go index ec8e8616..3a6474f6 100644 --- a/cmd-copy.go +++ b/cmd-copy.go @@ -18,7 +18,6 @@ package main import ( "io" - "os" "runtime" "sync" @@ -67,12 +66,12 @@ func doCopy(sourceURL string, sourceConfig *hostConfig, targetURL string, target // runCopyCmd is bound to sub-command func runCopyCmd(ctx *cli.Context) { - var retCode int - if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code } - + if !isMcConfigExist() { + console.Fatalln("\"mc\" is not configured. Please run \"mc config generate\".") + } config, err := getMcConfig() if err != nil { console.Debugln(iodine.New(err, nil)) @@ -140,7 +139,4 @@ func runCopyCmd(ctx *cli.Context) { } wg.Wait() bar.Finish() - - os.Exit(retCode) - } diff --git a/cmd-sync.go b/cmd-sync.go index a4b9bf89..13555422 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -16,15 +16,12 @@ package main -import "github.com/minio/cli" +import ( + "github.com/minio/cli" + "github.com/minio/mc/pkg/console" + "github.com/minio/minio/pkg/iodine" +) -func runSyncCmd(ctx *cli.Context) { - if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { - cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code - } -} - -/* func runSyncCmd(ctx *cli.Context) { if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code @@ -39,7 +36,7 @@ func runSyncCmd(ctx *cli.Context) { } // Convert arguments to URLs: expand alias, fix format... - urls, err := getExpandedURLs(ctx.Args(), config.Aliases) + _, err = getExpandedURLs(ctx.Args(), config.Aliases) if err != nil { switch e := iodine.ToError(err).(type) { case errUnsupportedScheme: @@ -50,9 +47,10 @@ func runSyncCmd(ctx *cli.Context) { console.Fatalf("Unable to parse arguments. Reason: [%s].\n", e) } } - runCopyCmdSingleSourceMultipleTargets(urls) + // runCopyCmdSingleSourceMultipleTargets(urls) } +/* func runCopyCmdSingleSourceMultipleTargets(urls []string) { sourceURL := urls[0] // first arg is source targetURLs := urls[1:] // all other are targets diff --git a/copy-url.go b/copy-url.go index 8e4c4864..153d51cf 100644 --- a/copy-url.go +++ b/copy-url.go @@ -160,7 +160,6 @@ func guessCopyURLType(sourceURLs []string, targetURL string) copyURLsType { // prepareCopyURLsTypeA - prepares target and source URLs for copying. func prepareCopyURLsTypeA(sourceURL string, targetURL string) *copyURLs { - sourceClient, err := source2Client(sourceURL) if err != nil { return ©URLs{Error: iodine.New(err, nil)} @@ -252,17 +251,15 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) *copyURLs { // prepareCopyRecursiveURLTypeC - prepares target and source URLs for copying. func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *copyURLs { copyURLsCh := make(chan *copyURLs) - go func(sourceURL, targetURL string, copyURLsCh chan *copyURLs) { defer close(copyURLsCh) - if !isURLRecursive(sourceURL) { // Source is not of recursive type. copyURLsCh <- ©URLs{Error: iodine.New(fmt.Errorf("Source [%s] is not recursive.", sourceURL), nil)} return } - sourceURL = stripRecursiveURL(sourceURL) + sourceURL = stripRecursiveURL(sourceURL) sourceClient, err := source2Client(sourceURL) if err != nil { copyURLsCh <- ©URLs{Error: iodine.New(err, nil)} @@ -296,6 +293,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *copyURLs { copyURLsCh <- ©URLs{Error: iodine.New(fmt.Errorf("Target directory [%s] does not exist.", targetURL), nil)} return } + if !targetContent.Type.IsDir() { // Target exists, but is not a directory. copyURLsCh <- ©URLs{Error: iodine.New(fmt.Errorf("Target [%s] is not a directory.", targetURL), nil)} @@ -313,8 +311,8 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *copyURLs { // Source is not a regular file. Skip it for copy. continue } - // All OK.. We can proceed. Type B: source is a file, target is a directory and exists. + // All OK.. We can proceed. Type B: source is a file, target is a directory and exists. sourceURLParse, err := url.Parse(sourceURL) if err != nil { copyURLsCh <- ©URLs{Error: iodine.New(errInvalidSource{path: sourceURL}, nil)} diff --git a/errors.go b/errors.go index fdeda594..3ed6bebb 100644 --- a/errors.go +++ b/errors.go @@ -122,5 +122,5 @@ type errInvalidTarget struct { } func (e errInvalidTarget) Error() string { - return "Invalid source " + e.path + return "Invalid target " + e.path }