Skip to content

Commit

Permalink
Various fixes for updating dircounts with watch enabled (#1881)
Browse files Browse the repository at this point in the history
* Fix file size bug when copying files

* Don't remove existing watches

* Bump fsnotify

* Ignore watching `/dev`
  • Loading branch information
joelim-work authored Jan 15, 2025
1 parent 8bfa3a6 commit 2095efa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
13 changes: 4 additions & 9 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (app *app) loop() {
}
}

app.setWatchPaths()
app.addWatchPaths()

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

app.ui.draw(app.nav)
case f := <-app.nav.fileChan:
dirs := app.nav.dirs
if app.ui.dirPrev != nil {
dirs = append(dirs, app.ui.dirPrev)
}

for _, dir := range dirs {
for _, dir := range app.nav.dirCache {
if dir.path != filepath.Dir(f.path) {
continue
}
Expand Down Expand Up @@ -638,7 +633,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
}
}

func (app *app) setWatchPaths() {
func (app *app) addWatchPaths() {
if !gOpts.watch || len(app.nav.dirs) == 0 {
return
}
Expand All @@ -654,5 +649,5 @@ func (app *app) setWatchPaths() {
}
}

app.watch.set(paths)
app.watch.add(paths)
}
4 changes: 2 additions & 2 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (e *setExpr) eval(app *app, args []string) {
if err == nil {
if gOpts.watch {
app.watch.start()
app.setWatchPaths()
app.addWatchPaths()
} else {
app.watch.stop()
}
Expand Down Expand Up @@ -582,7 +582,7 @@ func preChdir(app *app) {

func onChdir(app *app) {
app.nav.addJumpList()
app.setWatchPaths()
app.addWatchPaths()
if cmd, ok := gOpts.cmds["on-cd"]; ok {
cmd.eval(app, nil)
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23
require (
github.com/Xuanwo/go-locale v1.1.2
github.com/djherbis/times v1.6.0
github.com/fsnotify/fsnotify v1.7.0
github.com/fsnotify/fsnotify v1.8.0
github.com/gdamore/tcell/v2 v2.7.4
github.com/mattn/go-runewidth v0.0.16
golang.org/x/sys v0.28.0
Expand All @@ -14,7 +14,7 @@ require (
)

require (
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand All @@ -16,6 +20,8 @@ github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down
13 changes: 5 additions & 8 deletions watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,16 @@ func (watch *watch) stop() {
watch.events = nil
}

func (watch *watch) set(paths map[string]bool) {
func (watch *watch) add(paths map[string]bool) {
if watch.watcher == nil {
return
}

for _, path := range watch.watcher.WatchList() {
if !paths[path] {
watch.watcher.Remove(path)
}
}

for path := range paths {
watch.watcher.Add(path)
// ignore /dev since write updates to /dev/tty causes high cpu usage
if path != "/dev" {
watch.watcher.Add(path)
}
}
}

Expand Down

0 comments on commit 2095efa

Please sign in to comment.