Add Remove() method for session, Close() becomes the new Save()

This commit is contained in:
Harshavardhana
2015-07-25 19:56:38 -07:00
parent d7e707030d
commit 04fbff76a9
5 changed files with 34 additions and 13 deletions
+5 -3
View File
@@ -170,6 +170,7 @@ func doPrepareCastURLs(session *sessionV2, trapCh <-chan bool) {
totalObjects++
case <-trapCh:
session.Close() // If we are interrupted during the URL scanning, we drop the session.
session.Remove()
os.Exit(0)
}
}
@@ -222,7 +223,7 @@ func doCastCmdSession(session *sessionV2) {
console.Errorf("Failed to cast ‘%s’, %s\n", sURLs.SourceContent.Name, NewIodine(sURLs.Error))
}
case <-trapCh: // Receive interrupt notification.
session.Save()
session.Close()
session.Info()
os.Exit(0)
}
@@ -268,16 +269,17 @@ func runCastCmd(ctx *cli.Context) {
session.Header.CommandType = "cast"
session.Header.RootPath, err = os.Getwd()
if err != nil {
session.Close()
session.Remove()
console.Fatalf("Unable to get current working folder. %s\n", err)
}
// extract URLs.
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
session.Remove()
console.Fatalf("One or more unknown URL types found in %s. %s\n", ctx.Args(), err)
}
doCastCmdSession(session)
session.Remove()
}
+5 -3
View File
@@ -171,6 +171,7 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
totalObjects++
case <-trapCh:
session.Close() // If we are interrupted during the URL scanning, we drop the session.
session.Remove()
os.Exit(0)
}
}
@@ -224,7 +225,7 @@ func doCopyCmdSession(session *sessionV2) {
console.Errorf("Failed to copy ‘%s’, %s\n", cpURLs.SourceContent.Name, NewIodine(iodine.New(cpURLs.Error, nil)))
}
case <-trapCh: // Receive interrupt notification.
session.Save()
session.Close()
session.Info()
os.Exit(0)
}
@@ -271,16 +272,17 @@ func runCopyCmd(ctx *cli.Context) {
session.Header.CommandType = "cp"
session.Header.RootPath, err = os.Getwd()
if err != nil {
session.Close()
session.Remove()
console.Fatalf("Unable to get current working folder. %s\n", err)
}
// extract URLs.
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
session.Remove()
console.Fatalf("One or more unknown URL types found %s. %s\n", ctx.Args(), err)
}
doCopyCmdSession(session)
session.Remove()
}
+7 -4
View File
@@ -88,7 +88,7 @@ func clearSession(sid string) {
if err != nil {
console.Fatalf("Unable to load session ‘%s’, %s", sid, NewIodine(iodine.New(err, nil)))
}
session.Close()
session.Remove()
}
return
}
@@ -102,7 +102,7 @@ func clearSession(sid string) {
console.Fatalf("Unable to load session ‘%s’, %s", sid, NewIodine(iodine.New(err, nil)))
}
if session != nil {
session.Close()
session.Remove()
}
}
@@ -168,9 +168,12 @@ func runSessionCmd(ctx *cli.Context) {
sessionExecute(s)
err = s.Close()
if err != nil {
console.Fatalln("Unable to close session file properly. %s\n", err)
console.Fatalf("Unable to close session file properly. %s\n", err)
}
err = s.Remove()
if err != nil {
console.Fatalf("Unable to clear session files properly. %s\n", err)
}
// change dir back
os.Chdir(savedCwd)
+15 -1
View File
@@ -138,7 +138,20 @@ func (s *sessionV2) Close() error {
return NewIodine(iodine.New(err, nil))
}
err = os.Remove(getSessionDataFile(s.SessionID))
qs, err := quick.New(s.Header)
if err != nil {
return NewIodine(iodine.New(err, nil))
}
return qs.Save(getSessionFile(s.SessionID))
}
// Remove removes all the session files.
func (s *sessionV2) Remove() error {
s.mutex.Lock()
defer s.mutex.Unlock()
err := os.Remove(getSessionDataFile(s.SessionID))
if err != nil {
return NewIodine(iodine.New(err, nil))
}
@@ -151,6 +164,7 @@ func (s *sessionV2) Close() error {
if err != nil {
return NewIodine(iodine.New(err, nil))
}
return nil
}
+2 -2
View File
@@ -40,14 +40,14 @@ func (s *CmdTestSuite) TestSession(c *C) {
c.Assert(session.Header.CommandArgs, IsNil)
c.Assert(len(session.SessionID), Equals, 8)
err = session.Save()
err = session.Close()
c.Assert(err, IsNil)
savedSession, err := loadSessionV2(session.SessionID)
c.Assert(err, IsNil)
c.Assert(session.SessionID, Equals, savedSession.SessionID)
err = session.Close()
err = session.Remove()
c.Assert(err, IsNil)
}