From 3b5759efba1456f62cb42d8c618e9c9340d3d350 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 10 Nov 2016 23:43:54 +0300 Subject: [PATCH] sync with server on startup Mentioned in #13 and #36. --- client.go | 6 ++++++ eval.go | 8 +------- nav.go | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index 1fdda5e..fa3b845 100644 --- a/client.go +++ b/client.go @@ -30,6 +30,12 @@ func client() { app.ui.loadFile(app.nav) + if err := app.nav.sync(); err != nil { + msg := fmt.Sprintf("sync: %s", err) + app.ui.message = msg + log.Printf(msg) + } + if _, err := os.Stat(gConfigPath); err == nil { log.Printf("reading configuration file: %s", gConfigPath) diff --git a/eval.go b/eval.go index d527f94..6aa86f9 100644 --- a/eval.go +++ b/eval.go @@ -336,16 +336,10 @@ func (e *CallExpr) eval(app *App, args []string) { app.ui.renew() app.nav.renew(app.ui.wins[0].h) case "sync": - list, copy, err := loadFiles() - if err != nil { + if err := app.nav.sync(); err != nil { msg := fmt.Sprintf("sync: %s", err) app.ui.message = msg log.Printf(msg) - return - } - app.nav.saves = make(map[string]bool) - for _, f := range list { - app.nav.saves[f] = copy } case "echo": app.ui.message = strings.Join(e.args, " ") diff --git a/nav.go b/nav.go index fe8caa9..3767ffe 100644 --- a/nav.go +++ b/nav.go @@ -461,6 +461,20 @@ func (nav *Nav) put() error { return nil } +func (nav *Nav) sync() error { + list, copy, err := loadFiles() + if err != nil { + return err + } + + nav.saves = make(map[string]bool) + for _, f := range list { + nav.saves[f] = copy + } + + return nil +} + func (nav *Nav) currDir() *Dir { return nav.dirs[len(nav.dirs)-1] }