Invalidate cache for recreated files

This commit is contained in:
Joe Lim committed 2024-06-22 17:17:35 +10:00
1 parent adaf464fea
commit c2879498a2
3 files changed
+17 -3

No files matched your search

+4 -1
View File
@@ -45,7 +45,7 @@ func newApp(ui *ui, nav *nav) *app {
nav: nav,
ticker: new(time.Ticker),
quitChan: quitChan,
watch: newWatch(nav.dirChan, nav.fileChan),
watch: newWatch(nav.dirChan, nav.fileChan, nav.delChan),
}
sigChan := make(chan os.Signal, 1)
@@ -457,6 +457,9 @@ func (app *app) loop() {
app.ui.loadFile(app, false)
app.ui.draw(app.nav)
case path := <-app.nav.delChan:
delete(app.nav.dirCache, path)
delete(app.nav.regCache, path)
case ev := <-app.ui.evChan:
e := app.ui.readEvent(ev, app.nav)
if e == nil {
+2
View File
@@ -439,6 +439,7 @@ type nav struct {
dirChan chan *dir
regChan chan *reg
fileChan chan *file
delChan chan string
dirCache map[string]*dir
regCache map[string]*reg
saves map[string]bool
@@ -585,6 +586,7 @@ func newNav(height int) *nav {
dirChan: make(chan *dir),
regChan: make(chan *reg),
fileChan: make(chan *file),
delChan: make(chan string),
dirCache: make(map[string]*dir),
regCache: make(map[string]*reg),
saves: make(map[string]bool),
+11 -2
View File
@@ -18,9 +18,10 @@ type watch struct {
updateTimer *time.Timer
dirChan chan<- *dir
fileChan chan<- *file
delChan chan<- string
}
func newWatch(dirChan chan<- *dir, fileChan chan<- *file) *watch {
func newWatch(dirChan chan<- *dir, fileChan chan<- *file, delChan chan<- string) *watch {
return &watch{
quit: make(chan struct{}),
loads: make(map[string]bool),
@@ -29,6 +30,7 @@ func newWatch(dirChan chan<- *dir, fileChan chan<- *file) *watch {
updateTimer: time.NewTimer(0),
dirChan: dirChan,
fileChan: fileChan,
delChan: delChan,
}
}
@@ -81,7 +83,14 @@ func (watch *watch) loop() {
for {
select {
case ev := <-watch.events:
if ev.Has(fsnotify.Create) || ev.Has(fsnotify.Remove) || ev.Has(fsnotify.Rename) {
if ev.Has(fsnotify.Create) {
dir := filepath.Dir(ev.Name)
watch.addLoad(dir)
watch.addUpdate(dir)
}
if ev.Has(fsnotify.Remove) || ev.Has(fsnotify.Rename) {
watch.delChan <- ev.Name
dir := filepath.Dir(ev.Name)
watch.addLoad(dir)
watch.addUpdate(dir)