From d76cdd35d65c50b077d99e033a3ea7c28740ef52 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 29 Jun 2015 13:39:48 -0700 Subject: [PATCH] Save session rootPath to handle sessions from anywhere, relative or absolute --- cmd-cp.go | 1 + cmd-session.go | 23 ++++++++++++++++++----- cmd-sync.go | 1 + session.go | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd-cp.go b/cmd-cp.go index 56128972..ace24658 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -244,6 +244,7 @@ func runCopyCmd(ctx *cli.Context) { }) } s.CommandType = "cp" + s.RootPath, _ = os.Getwd() // extract URLs. s.URLs, err = args2URLs(ctx.Args()) diff --git a/cmd-session.go b/cmd-session.go index 79efe5d2..17173d7d 100644 --- a/cmd-session.go +++ b/cmd-session.go @@ -186,7 +186,7 @@ func runSessionCmd(ctx *cli.Context) { if err := createSessionDir(); err != nil { console.Fatals(ErrorMessage{ Message: "Failed with", - Error: iodine.ToError(err), + Error: iodine.New(err, nil), }) } } @@ -197,7 +197,7 @@ func runSessionCmd(ctx *cli.Context) { if err != nil { console.Fatals(ErrorMessage{ Message: "Failed with", - Error: iodine.ToError(err), + Error: iodine.New(err, nil), }) } case "resume": @@ -212,9 +212,20 @@ func runSessionCmd(ctx *cli.Context) { if err != nil { console.Fatals(ErrorMessage{ Message: "Failed with", - Error: iodine.ToError(err), + Error: iodine.New(err, nil), }) } + savedCwd, err := os.Getwd() + if err != nil { + console.Fatals(ErrorMessage{ + Message: "Failed with", + Error: iodine.New(err, nil), + }) + } + if s.RootPath != "" { + // chdir to RootPath + os.Chdir(s.RootPath) + } var bar barSend // set up progress bar if !globalQuietFlag { @@ -226,9 +237,11 @@ func runSessionCmd(ctx *cli.Context) { if err := clearSession(sid); err != nil { console.Fatals(ErrorMessage{ Message: "Failed with", - Error: iodine.ToError(err), + Error: iodine.New(err, nil), }) } + // change dir back + os.Chdir(savedCwd) } // purge a requested pending session, if "*" purge everything case "clear": @@ -241,7 +254,7 @@ func runSessionCmd(ctx *cli.Context) { if err := clearSession(strings.TrimSpace(ctx.Args().Tail().First())); err != nil { console.Fatals(ErrorMessage{ Message: "Failed with", - Error: iodine.ToError(err), + Error: iodine.New(err, nil), }) } default: diff --git a/cmd-sync.go b/cmd-sync.go index f7ebe0a7..994a94f2 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -246,6 +246,7 @@ func runSyncCmd(ctx *cli.Context) { }) } s.CommandType = "sync" + s.RootPath, _ = os.Getwd() // extract URLs. s.URLs, err = args2URLs(ctx.Args()) diff --git a/session.go b/session.go index 9838c6d0..520d7919 100644 --- a/session.go +++ b/session.go @@ -34,6 +34,7 @@ type sessionV1 struct { Started time.Time `json:"started"` CommandType string `json:"command-type"` SessionID string `json:"session-id"` + RootPath string `json:"root-path"` URLs []string `json:"args"` Files map[string]bool `json:"files"`