From 93400c11a02702aa28a6d3e77eff399fd21c60bc Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sat, 19 Jul 2025 16:04:44 +1000 Subject: [PATCH] Misc improvements for `nav.checkDir` (#2050) * Misc improvements to `nav.checkDir` * Fix case where `dircache` is disabled * More fixes --- app.go | 2 ++ nav.go | 27 ++++++++++----------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/app.go b/app.go index 56b73ea5..6d510c1b 100644 --- a/app.go +++ b/app.go @@ -398,6 +398,8 @@ func (app *app) loop() { } app.nav.dirCache[d.path] = d + } else { + d.sort() } var oldCurrPath string diff --git a/nav.go b/nav.go index a5014340..9ec30b4f 100644 --- a/nav.go +++ b/nav.go @@ -169,7 +169,7 @@ func readdir(path string) ([]*file, error) { type dir struct { loading bool // directory is loading from disk - loadTime time.Time // current loading or last load time + loadTime time.Time // last load time ind int // index of current entry in files pos int // position of current entry in ui path string // full path of directory @@ -191,15 +191,13 @@ type dir struct { } func newDir(path string) *dir { - time := time.Now() - files, err := readdir(path) if err != nil { log.Printf("reading directory: %s", err) } return &dir{ - loadTime: time, + loadTime: time.Now(), path: path, files: files, allFiles: files, @@ -563,7 +561,6 @@ type nav struct { func (nav *nav) loadDirInternal(path string) *dir { d := &dir{ loading: true, - loadTime: time.Now(), path: path, sortby: getSortBy(path), dircounts: getDirCounts(path), @@ -578,10 +575,7 @@ func (nav *nav) loadDirInternal(path string) *dir { ignoredia: gOpts.ignoredia, } go func() { - d := newDir(path) - d.sort() - d.ind, d.pos = 0, 0 - nav.dirChan <- d + nav.dirChan <- newDir(path) }() return d } @@ -603,6 +597,10 @@ func (nav *nav) loadDir(path string) *dir { } func (nav *nav) checkDir(dir *dir) { + if dir.loading { + return + } + s, err := os.Stat(dir.path) if err != nil { log.Printf("getting directory info: %s", err) @@ -611,25 +609,20 @@ func (nav *nav) checkDir(dir *dir) { switch { case s.ModTime().After(dir.loadTime): - now := time.Now() - // XXX: Linux builtin exFAT drivers are able to predict modifications in the future // https://bugs.launchpad.net/ubuntu/+source/ubuntu-meta/+bug/1872504 - if s.ModTime().After(now) { + if s.ModTime().After(time.Now()) { return } dir.loading = true - dir.loadTime = now go func() { - nd := newDir(dir.path) - nav.dirChan <- nd + nav.dirChan <- newDir(dir.path) }() case dir.dircounts != getDirCounts(dir.path): dir.loading = true go func() { - nd := newDir(dir.path) - nav.dirChan <- nd + nav.dirChan <- newDir(dir.path) }() // Although toggling dircounts can affect sorting, it is already handled by // reloading the directory which should sort the files anyway, so it is not