From 23cee677b73c3a5b29bb22594a822524f3b21740 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 28 Apr 2015 11:58:40 -0700 Subject: [PATCH] Add ./mc cp to support --- cmd-cp.go | 30 ++++++++++++++++++++++++++++-- cmd-options.go | 27 +++++++++++++++++++++++++-- cmd-sync.go | 6 ++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 cmd-sync.go diff --git a/cmd-cp.go b/cmd-cp.go index 5bb00129..10e4977c 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -67,13 +67,39 @@ func runCopyCmdMultipleSources(methods clientMethods, urls []string) { console.Fatalf("Unable to read host configuration for the following targets %s from config file [%s]. Reason: [%s].\n", targetURL, mustGetMcConfigPath(), iodine.ToError(err)) } - sourceURLConfigMap, err := getHostConfigs(sourceURLs) + var newRecursiveSourceURLs []string + var newRegularSourceURLs []string + for _, sourceURL := range sourceURLs { + recursive := isURLRecursive(sourceURL) + // if recursive strip off the "..." + if recursive { + sourceURL = strings.TrimSuffix(sourceURL, recursiveSeparator) + newRecursiveSourceURLs = append(newRecursiveSourceURLs, sourceURL) + } else { + newRegularSourceURLs = append(newRegularSourceURLs, sourceURL) + } + } + for _, newRecursiveSourceURL := range newRecursiveSourceURLs { + newRecursiveSourceConfig, err := getHostConfig(newRecursiveSourceURL) + if err != nil { + log.Debug.Println(iodine.New(err, nil)) + console.Fatalf("Unable to read host configuration for the following targets %s from config file [%s]. Reason: [%s].\n", + newRecursiveSourceURL, mustGetMcConfigPath(), iodine.ToError(err)) + } + err = doCopySingleSourceRecursive(methods, newRecursiveSourceURL, targetURL, newRecursiveSourceConfig, targetConfig) + if err != nil { + log.Debug.Println(err) + console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", newRecursiveSourceURL, + targetURL, iodine.ToError(err)) + } + } + newRegularSourceURLConfigMap, err := getHostConfigs(newRegularSourceURLs) if err != nil { log.Debug.Println(iodine.New(err, nil)) console.Fatalf("Unable to read host configuration for source [%s] from config file [%s]. Reason: [%s].\n", sourceURLs, mustGetMcConfigPath(), iodine.ToError(err)) } - err = doCopyMultipleSources(methods, sourceURLConfigMap, targetURL, targetConfig) + err = doCopyMultipleSources(methods, newRegularSourceURLConfigMap, targetURL, targetConfig) if err != nil { log.Debug.Println(err) console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", sourceURLs, targetURL, iodine.ToError(err)) diff --git a/cmd-options.go b/cmd-options.go index d432dec6..ee3443d9 100644 --- a/cmd-options.go +++ b/cmd-options.go @@ -86,7 +86,7 @@ EXAMPLES: } cpCmd = cli.Command{ Name: "cp", - Usage: "Copy objects and files", + Usage: "Copy objects and files from multiple sources single destination", Action: runCopyCmd, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -165,6 +165,27 @@ EXAMPLES: `, } + syncCmd = cli.Command{ + Name: "sync", + Usage: "Copies files and objects from single source to multiple destinations", + Action: runSyncCmd, + CustomHelpTemplate: `NAME: + mc {{.Name}} - {{.Usage}} + +USAGE: + mc {{.Name}} TARGET [TARGET...] {{if .Description}} + +DESCRIPTION: + {{.Description}}{{end}}{{if .Flags}} + +FLAGS: + {{range .Flags}}{{.}} + {{end}}{{ end }} + +EXAMPLES: + +`, + } mbCmd = cli.Command{ Name: "mb", Usage: "Make a directory or bucket", @@ -247,7 +268,8 @@ EXAMPLES: // // ---- // ls List files and objects -// cp Copy objects and files +// cp Copy objects and files from multiple sources to single destination +// sync Copy objects and files from single source to multiple destionations // mb Make a bucket // access Set permissions [public, private, readonly] for buckets and folders. // cat Concantenate an object to standard output @@ -258,6 +280,7 @@ EXAMPLES: var commands = []cli.Command{ lsCmd, cpCmd, + syncCmd, catCmd, mbCmd, accessCmd, diff --git a/cmd-sync.go b/cmd-sync.go new file mode 100644 index 00000000..15c11ab0 --- /dev/null +++ b/cmd-sync.go @@ -0,0 +1,6 @@ +package main + +import "github.com/minio-io/cli" + +func runSyncCmd(ctx *cli.Context) { +}