Some cleanup, sync to be enabled
This commit is contained in:
+3
-7
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
+8
-10
@@ -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
|
||||
|
||||
+3
-5
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user