From d917951b5855b66fc85bf2b95e217b0f4237ae2f Mon Sep 17 00:00:00 2001 From: "Anand Babu (AB) Periasamy" Date: Thu, 12 Nov 2015 11:46:06 -0800 Subject: [PATCH] review session code --- cp-main.go | 6 +++--- mirror-main.go | 6 +++--- session-main.go | 8 ++++---- session-v2.go | 1 + session-v3.go | 19 ++++++++----------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/cp-main.go b/cp-main.go index 31289ab7..e85b6b5e 100644 --- a/cp-main.go +++ b/cp-main.go @@ -293,16 +293,16 @@ func doCopySession(session *sessionV3) { // handle more errors and save the session. switch cpURLs.Error.ToGoError().(type) { case *net.OpError: - gracefulSessionSave(session) + session.CloseAndDie() case net.Error: - gracefulSessionSave(session) + session.CloseAndDie() } } case <-trapCh: // Receive interrupt notification. if !globalQuietFlag && !globalJSONFlag { console.Eraseline() } - gracefulSessionSave(session) + session.CloseAndDie() } } }() diff --git a/mirror-main.go b/mirror-main.go index 5aafa5ff..0fa918ce 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -282,9 +282,9 @@ func doMirrorSession(session *sessionV3) { // handle more errors and save the session. switch sURLs.Error.ToGoError().(type) { case *net.OpError: - gracefulSessionSave(session) + session.CloseAndDie() case net.Error: - gracefulSessionSave(session) + session.CloseAndDie() } } case <-trapCh: // Receive interrupt notification. @@ -292,7 +292,7 @@ func doMirrorSession(session *sessionV3) { if !globalQuietFlag && !globalJSONFlag { console.Eraseline() } - gracefulSessionSave(session) + session.CloseAndDie() } } }() diff --git a/session-main.go b/session-main.go index bf0ecb27..7cd273f9 100644 --- a/session-main.go +++ b/session-main.go @@ -89,7 +89,7 @@ type clearSessionMessage struct { // String colorized clear session message func (c clearSessionMessage) String() string { - return console.Colorize("ClearSession", "Session ‘"+c.SessionID+"’ cleared successfully") + return console.Colorize("ClearSession", "Session ‘"+c.SessionID+"’ cleared successfully.") } // JSON jsonified clear session message @@ -190,12 +190,12 @@ func mainSession(ctx *cli.Context) { } savedCwd, e := os.Getwd() - fatalIf(probe.NewError(e), "Unable to verify your current working folder.") + fatalIf(probe.NewError(e), "Unable to determine current working folder.") if s.Header.RootPath != "" { // chdir to RootPath e = os.Chdir(s.Header.RootPath) - fatalIf(probe.NewError(e), "Unable to change our folder to root path while resuming session.") + fatalIf(probe.NewError(e), "Unable to change working folder to root path while resuming session.") } sessionExecute(s) err = s.Close() @@ -206,7 +206,7 @@ func mainSession(ctx *cli.Context) { // chdir back to saved path e = os.Chdir(savedCwd) - fatalIf(probe.NewError(e), "Unable to change our folder to saved path ‘"+savedCwd+"’.") + fatalIf(probe.NewError(e), "Unable to change working folder to saved path ‘"+savedCwd+"’.") // purge a requested pending session, if "all" purge everything case "clear": diff --git a/session-v2.go b/session-v2.go index 01d0d4f0..bb8390ad 100644 --- a/session-v2.go +++ b/session-v2.go @@ -63,6 +63,7 @@ func loadSessionV2(sid string) (*sessionV2Header, *probe.Error) { return nil, probe.NewError(err) } sessionHeader := &sessionV2Header{} + // V2 is actually v1.1. We later moved to a serial single digit version. sessionHeader.Version = "1.1.0" qs, err := quick.New(sessionHeader) if err != nil { diff --git a/session-v3.go b/session-v3.go index d7ea5a58..46419472 100644 --- a/session-v3.go +++ b/session-v3.go @@ -35,6 +35,7 @@ import ( func migrateSessionV2ToV3() { for _, sid := range getSessionIDs() { oldSessionV2Header, err := loadSessionV2(sid) + // 1.1.0 intermediate version number is actually v2. fatalIf(err.Trace(sid), "Unable to load version ‘1.1.0’. Migration failed please report this issue at https://github.com/minio/mc/issues.") if oldSessionV2Header.Version == "3" { return @@ -160,17 +161,6 @@ func newSessionV3() *sessionV3 { return s } -// String printer for SessionV3 -func (s sessionV3) Info() { - console.Infoln("Session safely terminated. To resume session ‘mc session resume " + s.SessionID + "’") -} - -func gracefulSessionSave(session *sessionV3) { - session.Close() - session.Info() - os.Exit(0) -} - // HasData provides true if this is a session resume, false otherwise. func (s sessionV3) HasData() bool { if s.Header.LastCopied == "" { @@ -268,6 +258,13 @@ func (s *sessionV3) Delete() *probe.Error { return nil } +// Close a session and exit. +func (s sessionV3) CloseAndDie() { + s.Close() + console.Infoln("Session safely terminated. To resume session ‘mc session resume " + s.SessionID + "’") + os.Exit(0) +} + // loadSessionV3 - reads session file if exists and re-initiates internal variables func loadSessionV3(sid string) (*sessionV3, *probe.Error) { if !isSessionDirExists() {