diff --git a/cp-main.go b/cp-main.go index 34d19ee8..f7b844ec 100644 --- a/cp-main.go +++ b/cp-main.go @@ -22,13 +22,13 @@ import ( "fmt" "io" "math" + "net" "os" "runtime" "sync" "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" ) @@ -257,32 +257,25 @@ func doCopyCmdSession(session *sessionV2) { if !globalQuietFlag && !globalJSONFlag { console.Eraseline() } + errorIf(cpURLs.Error.Trace(), fmt.Sprintf("Failed to copy ‘%s’.", cpURLs.SourceContent.Name)) + // 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. 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 + case *net.OpError: + gracefulSessionSave(session) + case net.Error: + gracefulSessionSave(session) } - 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) } case <-trapCh: // Receive interrupt notification. if !globalQuietFlag && !globalJSONFlag { console.Eraseline() } - session.Close() - session.Info() - os.Exit(0) + gracefulSessionSave(session) } } }() diff --git a/mirror-main.go b/mirror-main.go index 06adec6d..48fb2064 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -22,13 +22,13 @@ import ( "fmt" "io" "math" + "net" "os" "runtime" "sync" "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" ) @@ -256,33 +256,26 @@ func doMirrorCmdSession(session *sessionV2) { if !globalQuietFlag && !globalJSONFlag { console.Eraseline() } + // 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. + 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 + case *net.OpError: + gracefulSessionSave(session) + case net.Error: + gracefulSessionSave(session) } - 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) } case <-trapCh: // Receive interrupt notification. // Print in new line and adjust to top so that we don't print over the ongoing progress bar if !globalQuietFlag && !globalJSONFlag { console.Eraseline() } - session.Close() - session.Info() - os.Exit(0) + gracefulSessionSave(session) } } }() diff --git a/session-v2.go b/session-v2.go index 60ad4681..910d5335 100644 --- a/session-v2.go +++ b/session-v2.go @@ -131,6 +131,12 @@ func (s sessionV2) Info() { console.Infoln("Session safely terminated. To resume session ‘mc session resume " + s.SessionID + "’") } +func gracefulSessionSave(session *sessionV2) { + session.Close() + session.Info() + os.Exit(0) +} + // HasData provides true if this is a session resume, false otherwise. func (s sessionV2) HasData() bool { if s.Header.LastCopied == "" {