From fd82bbf453f65dc85ea600f83267a6ef42369cd1 Mon Sep 17 00:00:00 2001 From: Krishna Srinivas Date: Tue, 17 Nov 2015 16:49:14 -0800 Subject: [PATCH] exit mc on any critical error during cp/mirror #1378 --- cp-main.go | 27 +++++++++++++++------------ mirror-main.go | 27 +++++++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/cp-main.go b/cp-main.go index 55a1aae7..81a98840 100644 --- a/cp-main.go +++ b/cp-main.go @@ -22,14 +22,15 @@ import ( "fmt" "io" "math" - "net" "os" "runtime" "strings" "sync" + "syscall" "github.com/fatih/color" "github.com/minio/cli" + "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" "github.com/minio/minio-xl/pkg/probe" "github.com/minio/pb" @@ -254,7 +255,7 @@ func doPrepareCopyURLs(session *sessionV3, trapCh <-chan bool) { } func doCopySession(session *sessionV3) { - trapCh := signalTrap(os.Interrupt, os.Kill) + trapCh := signalTrap(os.Interrupt, syscall.SIGTERM) if !session.HasData() { doPrepareCopyURLs(session, trapCh) @@ -314,18 +315,20 @@ func doCopySession(session *sessionV3) { console.Eraseline() } errorIf(cpURLs.Error.Trace(), fmt.Sprintf("Failed to copy ā€˜%s’.", cpURLs.SourceContent.URL.String())) - // all the cases which are handled where session should be saved are contained in the following - // switch case, we shouldn't be saving sessions for all errors since some errors might need to be - // reported to user properly. - // - // All other critical cases should be handled properly gracefully - // handle more errors and save the session. + // for all non critical errors we can continue for the remaining files switch cpURLs.Error.ToGoError().(type) { - case *net.OpError: - session.CloseAndDie() - case net.Error: - session.CloseAndDie() + // handle this specifically for filesystem related errors. + case client.BrokenSymlink: + continue + case client.TooManyLevelsSymlink: + continue + case client.PathNotFound: + continue + case client.PathInsufficientPermission: + continue } + // for critical errors we should exit. Session can be resumed after the user figures out the problem + session.CloseAndDie() } case <-trapCh: // Receive interrupt notification. if !globalQuietFlag && !globalJSONFlag { diff --git a/mirror-main.go b/mirror-main.go index a055f8cc..dda4ff40 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -22,13 +22,14 @@ import ( "fmt" "io" "math" - "net" "os" "runtime" "sync" + "syscall" "github.com/fatih/color" "github.com/minio/cli" + "github.com/minio/mc/pkg/client" "github.com/minio/mc/pkg/console" "github.com/minio/minio-xl/pkg/probe" "github.com/minio/pb" @@ -253,7 +254,7 @@ func doPrepareMirrorURLs(session *sessionV3, trapCh <-chan bool) { // Session'fied mirror command. func doMirrorSession(session *sessionV3) { - trapCh := signalTrap(os.Interrupt, os.Kill) + trapCh := signalTrap(os.Interrupt, syscall.SIGTERM) if !session.HasData() { doPrepareMirrorURLs(session, trapCh) @@ -311,18 +312,20 @@ func doMirrorSession(session *sessionV3) { console.Eraseline() } errorIf(sURLs.Error.Trace(), fmt.Sprintf("Failed to mirror ā€˜%s’.", sURLs.SourceContent.URL.String())) - // all the cases which are handled where session should be saved are contained in the following - // switch case, we shouldn't be saving sessions for all errors since some errors might need to be - // reported to user properly. - // - // All other critical cases should be handled properly gracefully - // handle more errors and save the session. + // for all non critical errors we can continue for the remaining files switch sURLs.Error.ToGoError().(type) { - case *net.OpError: - session.CloseAndDie() - case net.Error: - session.CloseAndDie() + // handle this specifically for filesystem related errors. + case client.BrokenSymlink: + continue + case client.TooManyLevelsSymlink: + continue + case client.PathNotFound: + continue + case client.PathInsufficientPermission: + continue } + // for critical errors we should exit. Session can be resumed after the user figures out the problem + session.CloseAndDie() } case <-trapCh: // Receive interrupt notification. // Print in new line and adjust to top so that we don't print over the ongoing progress bar