Merge pull request #1035 from harshavardhana/mirror
Recursively progress along with errors if possible
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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}}
|
||||
|
||||
+9
-17
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user