From fe9f1b90320168b1325fa40b698719aed47dcbcc Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 28 Sep 2015 14:24:13 -0700 Subject: [PATCH] Do not exit for common filesystem errors - for cp, mirror - Broken Symlink - No Such file or directory, Permission Denied - Ignore broken directory symlinks --- cp-main.go | 17 ++++++++++++++++- mirror-main.go | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cp-main.go b/cp-main.go index 34323670..7b834292 100644 --- a/cp-main.go +++ b/cp-main.go @@ -28,6 +28,7 @@ import ( "github.com/fatih/color" "github.com/minio/cli" + "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" "github.com/minio/minio/pkg/probe" ) @@ -261,7 +262,21 @@ func doCopyCmdSession(session *sessionV2) { console.Printf("%c[2K\n", 27) console.Printf("%c[A", 27) } - errorIf(cpURLs.Error.Trace(), fmt.Sprintf("Failed to copy ‘%s’.", cpURLs.SourceContent.Name)) + switch cpURLs.Error.ToGoError().(type) { + // handle this specifically for filesystem + case client.ISBrokenSymlink: + errorIf(cpURLs.Error.Trace(), fmt.Sprintf("Failed to copy ‘%s’.", cpURLs.SourceContent.Name)) + continue + } + if os.IsNotExist(cpURLs.Error.ToGoError()) || os.IsPermission(cpURLs.Error.ToGoError()) { + if cpURLs.SourceContent != nil { + if cpURLs.SourceContent.Type.IsDir() && (cpURLs.SourceContent.Type&os.ModeSymlink == os.ModeSymlink) { + continue + } + } + errorIf(cpURLs.Error.Trace(), fmt.Sprintf("Failed to copy ‘%s’.", cpURLs.SourceContent.Name)) + continue + } session.Close() session.Info() os.Exit(0) diff --git a/mirror-main.go b/mirror-main.go index 9712e59c..4d102fc3 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -28,6 +28,7 @@ import ( "github.com/fatih/color" "github.com/minio/cli" + "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" "github.com/minio/minio/pkg/probe" ) @@ -259,7 +260,21 @@ func doMirrorCmdSession(session *sessionV2) { console.Printf("%c[2K\n", 27) console.Printf("%c[A", 27) } - errorIf(sURLs.Error.Trace(), "Failed to mirror.") + switch sURLs.Error.ToGoError().(type) { + // handle this specifically for filesystem + case client.ISBrokenSymlink: + errorIf(sURLs.Error.Trace(), "Failed to mirror.") + continue + } + if os.IsNotExist(sURLs.Error.ToGoError()) || os.IsPermission(sURLs.Error.ToGoError()) { + if sURLs.SourceContent != nil { + if sURLs.SourceContent.Type.IsDir() && (sURLs.SourceContent.Type&os.ModeSymlink == os.ModeSymlink) { + continue + } + } + errorIf(sURLs.Error.Trace(), "Failed to mirror.") + continue + } session.Close() session.Info() os.Exit(0)