From bc4c3c127bad1c8c38c2395bf3394bffdbf5d135 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 14 Aug 2016 15:45:24 +0300 Subject: [PATCH] do not follow symlinks on exit --- app.go | 16 ++++++++++++++++ main.go | 21 ++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app.go b/app.go index 8ec92da..080e9bc 100644 --- a/app.go +++ b/app.go @@ -34,6 +34,22 @@ func (app *App) handleInp() { for { if gExitFlag { log.Print("bye!") + + if gLastDirPath != "" { + f, err := os.Create(gLastDirPath) + if err != nil { + log.Print(err) + } + defer f.Close() + + dir := app.nav.currDir() + + _, err = f.WriteString(dir.path) + if err != nil { + log.Print(err) + } + } + return } e := app.ui.getExpr() diff --git a/main.go b/main.go index 730538c..74621df 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ var ( var ( gExitFlag bool + gLastDirPath string gSelectionPath string gSocketPath string gLogPath string @@ -62,7 +63,7 @@ func startServer() { func main() { serverMode := flag.Bool("server", false, "start server (automatic)") - lastDirPath := flag.String("last-dir-path", "", "path to the file to write the last dir on exit (to use for cd)") + flag.StringVar(&gLastDirPath, "last-dir-path", "", "path to the file to write the last dir on exit (to use for cd)") flag.StringVar(&gSelectionPath, "selection-path", "", "path to the file to write selected files on exit (to use as open file dialog)") flag.Parse() @@ -78,22 +79,4 @@ func main() { client() } - - if *lastDirPath != "" { - f, err := os.Create(*lastDirPath) - if err != nil { - log.Print(err) - } - defer f.Close() - - wd, err := os.Getwd() - if err != nil { - log.Print(err) - } - - _, err = f.WriteString(wd) - if err != nil { - log.Print(err) - } - } }