Invalidate cache for recreated files
This commit is contained in:
3 files changed
+17
-3
No files matched your search
@@ -45,7 +45,7 @@ func newApp(ui *ui, nav *nav) *app {
|
|||||||
nav: nav,
|
nav: nav,
|
||||||
ticker: new(time.Ticker),
|
ticker: new(time.Ticker),
|
||||||
quitChan: quitChan,
|
quitChan: quitChan,
|
||||||
watch: newWatch(nav.dirChan, nav.fileChan),
|
watch: newWatch(nav.dirChan, nav.fileChan, nav.delChan),
|
||||||
}
|
}
|
||||||
|
|
||||||
sigChan := make(chan os.Signal, 1)
|
sigChan := make(chan os.Signal, 1)
|
||||||
@@ -457,6 +457,9 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
app.ui.loadFile(app, false)
|
app.ui.loadFile(app, false)
|
||||||
app.ui.draw(app.nav)
|
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:
|
case ev := <-app.ui.evChan:
|
||||||
e := app.ui.readEvent(ev, app.nav)
|
e := app.ui.readEvent(ev, app.nav)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
|
|||||||
@@ -439,6 +439,7 @@ type nav struct {
|
|||||||
dirChan chan *dir
|
dirChan chan *dir
|
||||||
regChan chan *reg
|
regChan chan *reg
|
||||||
fileChan chan *file
|
fileChan chan *file
|
||||||
|
delChan chan string
|
||||||
dirCache map[string]*dir
|
dirCache map[string]*dir
|
||||||
regCache map[string]*reg
|
regCache map[string]*reg
|
||||||
saves map[string]bool
|
saves map[string]bool
|
||||||
@@ -585,6 +586,7 @@ func newNav(height int) *nav {
|
|||||||
dirChan: make(chan *dir),
|
dirChan: make(chan *dir),
|
||||||
regChan: make(chan *reg),
|
regChan: make(chan *reg),
|
||||||
fileChan: make(chan *file),
|
fileChan: make(chan *file),
|
||||||
|
delChan: make(chan string),
|
||||||
dirCache: make(map[string]*dir),
|
dirCache: make(map[string]*dir),
|
||||||
regCache: make(map[string]*reg),
|
regCache: make(map[string]*reg),
|
||||||
saves: make(map[string]bool),
|
saves: make(map[string]bool),
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ type watch struct {
|
|||||||
updateTimer *time.Timer
|
updateTimer *time.Timer
|
||||||
dirChan chan<- *dir
|
dirChan chan<- *dir
|
||||||
fileChan chan<- *file
|
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{
|
return &watch{
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
loads: make(map[string]bool),
|
loads: make(map[string]bool),
|
||||||
@@ -29,6 +30,7 @@ func newWatch(dirChan chan<- *dir, fileChan chan<- *file) *watch {
|
|||||||
updateTimer: time.NewTimer(0),
|
updateTimer: time.NewTimer(0),
|
||||||
dirChan: dirChan,
|
dirChan: dirChan,
|
||||||
fileChan: fileChan,
|
fileChan: fileChan,
|
||||||
|
delChan: delChan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +83,14 @@ func (watch *watch) loop() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case ev := <-watch.events:
|
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)
|
dir := filepath.Dir(ev.Name)
|
||||||
watch.addLoad(dir)
|
watch.addLoad(dir)
|
||||||
watch.addUpdate(dir)
|
watch.addUpdate(dir)
|
||||||
|
|||||||
Reference in new issue
Block a user