Misc improvements for nav.checkDir (#2050)
* Misc improvements to `nav.checkDir` * Fix case where `dircache` is disabled * More fixes
This commit is contained in:
1 parent
c31b92491f
commit
93400c11a0
2 files changed
+12
-17
No files matched your search
@@ -398,6 +398,8 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
app.nav.dirCache[d.path] = d
|
||||
} else {
|
||||
d.sort()
|
||||
}
|
||||
|
||||
var oldCurrPath string
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user