review session code

This commit is contained in:
Anand Babu (AB) Periasamy
2015-11-12 11:46:06 -08:00
parent cdf1980666
commit d917951b58
5 changed files with 19 additions and 21 deletions
+3 -3
View File
@@ -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()
}
}
}()
+3 -3
View File
@@ -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()
}
}
}()
+4 -4
View File
@@ -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":
+1
View File
@@ -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 {
+8 -11
View File
@@ -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() {