Skip to content

Commit 2095efa

Browse files
authored
Various fixes for updating dircounts with watch enabled (#1881)
* Fix file size bug when copying files * Don't remove existing watches * Bump fsnotify * Ignore watching `/dev`
1 parent 8bfa3a6 commit 2095efa

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

app.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (app *app) loop() {
427427
}
428428
}
429429

430-
app.setWatchPaths()
430+
app.addWatchPaths()
431431

432432
app.ui.draw(app.nav)
433433
case r := <-app.nav.regChan:
@@ -442,12 +442,7 @@ func (app *app) loop() {
442442

443443
app.ui.draw(app.nav)
444444
case f := <-app.nav.fileChan:
445-
dirs := app.nav.dirs
446-
if app.ui.dirPrev != nil {
447-
dirs = append(dirs, app.ui.dirPrev)
448-
}
449-
450-
for _, dir := range dirs {
445+
for _, dir := range app.nav.dirCache {
451446
if dir.path != filepath.Dir(f.path) {
452447
continue
453448
}
@@ -638,7 +633,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
638633
}
639634
}
640635

641-
func (app *app) setWatchPaths() {
636+
func (app *app) addWatchPaths() {
642637
if !gOpts.watch || len(app.nav.dirs) == 0 {
643638
return
644639
}
@@ -654,5 +649,5 @@ func (app *app) setWatchPaths() {
654649
}
655650
}
656651

657-
app.watch.set(paths)
652+
app.watch.add(paths)
658653
}

eval.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (e *setExpr) eval(app *app, args []string) {
195195
if err == nil {
196196
if gOpts.watch {
197197
app.watch.start()
198-
app.setWatchPaths()
198+
app.addWatchPaths()
199199
} else {
200200
app.watch.stop()
201201
}
@@ -582,7 +582,7 @@ func preChdir(app *app) {
582582

583583
func onChdir(app *app) {
584584
app.nav.addJumpList()
585-
app.setWatchPaths()
585+
app.addWatchPaths()
586586
if cmd, ok := gOpts.cmds["on-cd"]; ok {
587587
cmd.eval(app, nil)
588588
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23
55
require (
66
github.com/Xuanwo/go-locale v1.1.2
77
github.com/djherbis/times v1.6.0
8-
github.com/fsnotify/fsnotify v1.7.0
8+
github.com/fsnotify/fsnotify v1.8.0
99
github.com/gdamore/tcell/v2 v2.7.4
1010
github.com/mattn/go-runewidth v0.0.16
1111
golang.org/x/sys v0.28.0
@@ -14,7 +14,7 @@ require (
1414
)
1515

1616
require (
17-
github.com/gdamore/encoding v1.0.0 // indirect
17+
github.com/gdamore/encoding v1.0.1 // indirect
1818
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
19-
github.com/rivo/uniseg v0.4.3 // indirect
19+
github.com/rivo/uniseg v0.4.7 // indirect
2020
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
44
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
55
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
66
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
7+
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
8+
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
79
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
810
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
11+
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
12+
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
913
github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
1014
github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
1115
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
@@ -16,6 +20,8 @@ github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
1620
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
1721
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
1822
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
23+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
24+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
1925
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2026
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2127
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

watch.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,16 @@ func (watch *watch) stop() {
6464
watch.events = nil
6565
}
6666

67-
func (watch *watch) set(paths map[string]bool) {
67+
func (watch *watch) add(paths map[string]bool) {
6868
if watch.watcher == nil {
6969
return
7070
}
7171

72-
for _, path := range watch.watcher.WatchList() {
73-
if !paths[path] {
74-
watch.watcher.Remove(path)
75-
}
76-
}
77-
7872
for path := range paths {
79-
watch.watcher.Add(path)
73+
// ignore /dev since write updates to /dev/tty causes high cpu usage
74+
if path != "/dev" {
75+
watch.watcher.Add(path)
76+
}
8077
}
8178
}
8279

0 commit comments

Comments
 (0)