sync with server on startup

Mentioned in #13 and #36.
This commit is contained in:
Gokcehan 2016-11-10 23:43:54 +03:00
parent 428f9e3dcb
commit 3b5759efba
3 changed files with 21 additions and 7 deletions

View File

@ -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)

View File

@ -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, " ")

14
nav.go
View File

@ -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]
}