From 492340b3d8d322a844af6e4de3ce7e691c38dae3 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 23 Aug 2015 02:20:15 -0700 Subject: [PATCH] Recursively progress along with errors if possible --- error.go | 4 ++-- flags.go | 10 +++++----- mirror-main.go | 2 +- mirror-url.go | 26 +++++++++----------------- pkg/client/fs/fs.go | 12 ++++++++++++ 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/error.go b/error.go index 0d306c21..8cf3e8e1 100644 --- a/error.go +++ b/error.go @@ -39,7 +39,7 @@ func fatalIf(err *probe.Error, msg string) { SysInfo map[string]string `json:"sysinfo"` }{ Message: msg, - Type: "Fatal", + Type: "fatal", Cause: err.ToGoError(), SysInfo: err.SysInfo, } @@ -73,7 +73,7 @@ func errorIf(err *probe.Error, msg string) { SysInfo map[string]string `json:"sysinfo"` }{ Message: msg, - Type: "Error", + Type: "error", Cause: err.ToGoError(), SysInfo: err.SysInfo, } diff --git a/flags.go b/flags.go index ba180baf..c80bbc53 100644 --- a/flags.go +++ b/flags.go @@ -28,27 +28,27 @@ var ( configFlag = cli.StringFlag{ Name: "config-folder, C", Value: mustGetMcConfigDir(), - Usage: "Path to configuration folder", + Usage: "Path to configuration folder.", } quietFlag = cli.BoolFlag{ Name: "quiet, q", - Usage: "Suppress chatty console output", + Usage: "Suppress chatty console output.", } mimicFlag = cli.BoolFlag{ Name: "mimic", - Usage: "Mimic operating system toolchain behavior wherever it makes sense", + Usage: "Behave like operating system tools. Use with shell aliases.", } jsonFlag = cli.BoolFlag{ Name: "json", - Usage: "Enable json formatted output", + Usage: "Enable json formatted output.", } debugFlag = cli.BoolFlag{ Name: "debug", - Usage: "Enable debugging output", + Usage: "Enable debugging output.", } // Add your new flags starting here diff --git a/mirror-main.go b/mirror-main.go index 9100aa56..ea6c408d 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -34,7 +34,7 @@ import ( // Help message. var mirrorCmd = cli.Command{ Name: "mirror", - Usage: "Mirror files and folders from a single source to many destinations.", + Usage: "Mirror folders recursively from a single source to many destinations.", Action: mainMirror, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} diff --git a/mirror-url.go b/mirror-url.go index 93da2b8c..31ff2e58 100644 --- a/mirror-url.go +++ b/mirror-url.go @@ -50,7 +50,6 @@ func (m mirrorURLs) isEmpty() bool { type MirrorMessage struct { Source string `json:"source"` Targets []string `json:"targets"` - Length int64 `json:"length"` } // String string printer for mirror message @@ -85,23 +84,15 @@ func checkMirrorSyntax(ctx *cli.Context) { /****** Generic rules *******/ // Source cannot be a folder (except when recursive) if !isURLRecursive(srcURL) { - _, srcContent, err := url2Stat(srcURL) - fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+srcURL+"’.") + fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Source ‘%s’ is not recursive. Use ‘%s...’ as argument to mirror recursively.", srcURL, srcURL)) + } + // Recursive source URL. + newSrcURL := stripRecursiveURL(srcURL) + _, srcContent, err := url2Stat(newSrcURL) + fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+newSrcURL+"’.") - if !srcContent.Type.IsRegular() { - if srcContent.Type.IsDir() { - fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively.", srcURL, srcURL)) - } - fatalIf(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a file.") - } - } else { // Recursive source URL. - newSrcURL := stripRecursiveURL(srcURL) - _, srcContent, err := url2Stat(newSrcURL) - fatalIf(err.Trace(srcURL), "Unable to stat source ‘"+newSrcURL+"’.") - - if srcContent.Type.IsRegular() { // Ellipses is supported only for folders. - fatalIf(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a folder.") - } + if srcContent.Type.IsRegular() { // Ellipses is supported only for folders. + fatalIf(probe.NewError(errInvalidArgument), "Source ‘"+srcURL+"’ is not a folder.") } if len(tgtURLs) == 0 && tgtURLs == nil { @@ -122,6 +113,7 @@ func checkMirrorSyntax(ctx *cli.Context) { fatalIf(probe.NewError(errInvalidArgument), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL)) } } + _, content, err := url2Stat(tgtURL) fatalIf(err.Trace(tgtURL), "Unable to stat target ‘"+tgtURL+"’.") if !content.Type.IsDir() { diff --git a/pkg/client/fs/fs.go b/pkg/client/fs/fs.go index e40ddc3a..035c0504 100644 --- a/pkg/client/fs/fs.go +++ b/pkg/client/fs/fs.go @@ -298,9 +298,17 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel } if err != nil { if strings.Contains(err.Error(), "operation not permitted") { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: probe.NewError(err), + } return nil } if os.IsPermission(err) { + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: probe.NewError(err), + } return nil } return err @@ -309,6 +317,10 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel fi, err = os.Stat(fp) if err != nil { if os.IsNotExist(err) || os.IsPermission(err) { // ignore broken symlinks and permission denied + contentCh <- client.ContentOnChannel{ + Content: nil, + Err: probe.NewError(err), + } return nil } return err