1
0
mirror of https://github.com/minio/mc.git synced 2025-11-16 11:02:34 +03:00

Some cleanup, sync to be enabled

This commit is contained in:
Harshavardhana
2015-05-16 02:16:13 -07:00
parent 164c8b8eea
commit af7d43dfe6
4 changed files with 15 additions and 23 deletions

View File

@@ -18,7 +18,6 @@ package main
import ( import (
"io" "io"
"os"
"runtime" "runtime"
"sync" "sync"
@@ -67,12 +66,12 @@ func doCopy(sourceURL string, sourceConfig *hostConfig, targetURL string, target
// runCopyCmd is bound to sub-command // runCopyCmd is bound to sub-command
func runCopyCmd(ctx *cli.Context) { func runCopyCmd(ctx *cli.Context) {
var retCode int
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code 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() config, err := getMcConfig()
if err != nil { if err != nil {
console.Debugln(iodine.New(err, nil)) console.Debugln(iodine.New(err, nil))
@@ -140,7 +139,4 @@ func runCopyCmd(ctx *cli.Context) {
} }
wg.Wait() wg.Wait()
bar.Finish() bar.Finish()
os.Exit(retCode)
} }

View File

@@ -16,15 +16,12 @@
package main 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) { func runSyncCmd(ctx *cli.Context) {
if len(ctx.Args()) < 2 || ctx.Args().First() == "help" { if len(ctx.Args()) < 2 || ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, "sync", 1) // last argument is exit code 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... // Convert arguments to URLs: expand alias, fix format...
urls, err := getExpandedURLs(ctx.Args(), config.Aliases) _, err = getExpandedURLs(ctx.Args(), config.Aliases)
if err != nil { if err != nil {
switch e := iodine.ToError(err).(type) { switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme: case errUnsupportedScheme:
@@ -50,9 +47,10 @@ func runSyncCmd(ctx *cli.Context) {
console.Fatalf("Unable to parse arguments. Reason: [%s].\n", e) console.Fatalf("Unable to parse arguments. Reason: [%s].\n", e)
} }
} }
runCopyCmdSingleSourceMultipleTargets(urls) // runCopyCmdSingleSourceMultipleTargets(urls)
} }
/*
func runCopyCmdSingleSourceMultipleTargets(urls []string) { func runCopyCmdSingleSourceMultipleTargets(urls []string) {
sourceURL := urls[0] // first arg is source sourceURL := urls[0] // first arg is source
targetURLs := urls[1:] // all other are targets targetURLs := urls[1:] // all other are targets

View File

@@ -160,7 +160,6 @@ func guessCopyURLType(sourceURLs []string, targetURL string) copyURLsType {
// prepareCopyURLsTypeA - prepares target and source URLs for copying. // prepareCopyURLsTypeA - prepares target and source URLs for copying.
func prepareCopyURLsTypeA(sourceURL string, targetURL string) *copyURLs { func prepareCopyURLsTypeA(sourceURL string, targetURL string) *copyURLs {
sourceClient, err := source2Client(sourceURL) sourceClient, err := source2Client(sourceURL)
if err != nil { if err != nil {
return &copyURLs{Error: iodine.New(err, nil)} return &copyURLs{Error: iodine.New(err, nil)}
@@ -252,17 +251,15 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) *copyURLs {
// prepareCopyRecursiveURLTypeC - prepares target and source URLs for copying. // prepareCopyRecursiveURLTypeC - prepares target and source URLs for copying.
func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *copyURLs { func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *copyURLs {
copyURLsCh := make(chan *copyURLs) copyURLsCh := make(chan *copyURLs)
go func(sourceURL, targetURL string, copyURLsCh chan *copyURLs) { go func(sourceURL, targetURL string, copyURLsCh chan *copyURLs) {
defer close(copyURLsCh) defer close(copyURLsCh)
if !isURLRecursive(sourceURL) { if !isURLRecursive(sourceURL) {
// Source is not of recursive type. // Source is not of recursive type.
copyURLsCh <- &copyURLs{Error: iodine.New(fmt.Errorf("Source [%s] is not recursive.", sourceURL), nil)} copyURLsCh <- &copyURLs{Error: iodine.New(fmt.Errorf("Source [%s] is not recursive.", sourceURL), nil)}
return return
} }
sourceURL = stripRecursiveURL(sourceURL)
sourceURL = stripRecursiveURL(sourceURL)
sourceClient, err := source2Client(sourceURL) sourceClient, err := source2Client(sourceURL)
if err != nil { if err != nil {
copyURLsCh <- &copyURLs{Error: iodine.New(err, nil)} copyURLsCh <- &copyURLs{Error: iodine.New(err, nil)}
@@ -296,6 +293,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan *copyURLs {
copyURLsCh <- &copyURLs{Error: iodine.New(fmt.Errorf("Target directory [%s] does not exist.", targetURL), nil)} copyURLsCh <- &copyURLs{Error: iodine.New(fmt.Errorf("Target directory [%s] does not exist.", targetURL), nil)}
return return
} }
if !targetContent.Type.IsDir() { if !targetContent.Type.IsDir() {
// Target exists, but is not a directory. // Target exists, but is not a directory.
copyURLsCh <- &copyURLs{Error: iodine.New(fmt.Errorf("Target [%s] is not a directory.", targetURL), nil)} copyURLsCh <- &copyURLs{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. // Source is not a regular file. Skip it for copy.
continue 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) sourceURLParse, err := url.Parse(sourceURL)
if err != nil { if err != nil {
copyURLsCh <- &copyURLs{Error: iodine.New(errInvalidSource{path: sourceURL}, nil)} copyURLsCh <- &copyURLs{Error: iodine.New(errInvalidSource{path: sourceURL}, nil)}

View File

@@ -122,5 +122,5 @@ type errInvalidTarget struct {
} }
func (e errInvalidTarget) Error() string { func (e errInvalidTarget) Error() string {
return "Invalid source " + e.path return "Invalid target " + e.path
} }