Refactor Nav API around symlinks handling (mostly) (#33)

* gofmt ui.go

* Refactor Nav API around symlinks handling (mostly)

1. Get both `Lstat` and `Stat` while reading the files. Stat info is
   used by default, but we still can tell it's a link if needed.
2. Remove all other `Stat` calls from different places.
3. Handle hidden files while reading.
4. `currFile` now returns error if there are no files.
5. `currEmpty` and `currPath` not longer necessary, removed.
6. `open` now returns a named error ErrNotDir, where expected.

7. Side effect: Links that point at directories are now sorted among
   "actual" directories.
This commit is contained in:
Karol Woźniak authored and gokcehan committed 2016-10-24 22:18:31 +03:00
1 parent 880615ddd0
commit c9b4389c65
4 files changed
+127 -111

No files matched your search

+12 -22
View File
@@ -178,31 +178,16 @@ func (e *CallExpr) eval(app *App, args []string) {
}
app.ui.loadFile(app.nav)
case "open":
dir := app.nav.currDir()
if len(dir.fi) == 0 {
return
}
path := app.nav.currPath()
f, err := os.Stat(path)
if err != nil {
msg := fmt.Sprintf("open: %s", err)
app.ui.message = msg
log.Print(msg)
return
}
if f.IsDir() {
if err := app.nav.open(); err != nil {
app.ui.message = err.Error()
log.Print(err)
return
}
err := app.nav.open()
if err == nil {
app.ui.loadFile(app.nav)
return
}
if err != ErrNotDir {
app.ui.message = err.Error()
log.Print(err)
return
}
if gSelectionPath != "" {
out, err := os.Create(gSelectionPath)
@@ -211,9 +196,14 @@ func (e *CallExpr) eval(app *App, args []string) {
}
defer out.Close()
var path string
if len(app.nav.marks) != 0 {
marks := app.nav.currMarks()
path = strings.Join(marks, "\n")
} else if curr, err := app.nav.currFile(); err == nil {
path = curr.Path
} else {
return
}
_, err = out.WriteString(path)