Ensure InotifyTracker attempts to send all FileEvents
This commit is contained in:
parent
f053e2cd0c
commit
a5dc0d39ba
|
@ -17,6 +17,7 @@ type InotifyTracker struct {
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
watcher *fsnotify.Watcher
|
watcher *fsnotify.Watcher
|
||||||
chans map[string]chan *fsnotify.FileEvent
|
chans map[string]chan *fsnotify.FileEvent
|
||||||
|
done map[string]chan bool
|
||||||
watch chan *watchInfo
|
watch chan *watchInfo
|
||||||
remove chan string
|
remove chan string
|
||||||
error chan error
|
error chan error
|
||||||
|
@ -32,6 +33,7 @@ var (
|
||||||
shared = &InotifyTracker{
|
shared = &InotifyTracker{
|
||||||
mux: sync.Mutex{},
|
mux: sync.Mutex{},
|
||||||
chans: make(map[string]chan *fsnotify.FileEvent),
|
chans: make(map[string]chan *fsnotify.FileEvent),
|
||||||
|
done: make(map[string]chan bool),
|
||||||
watch: make(chan *watchInfo),
|
watch: make(chan *watchInfo),
|
||||||
remove: make(chan string),
|
remove: make(chan string),
|
||||||
error: make(chan error),
|
error: make(chan error),
|
||||||
|
@ -70,6 +72,14 @@ func (shared *InotifyTracker) RemoveWatch(fname string) {
|
||||||
// start running the shared InotifyTracker if not already running
|
// start running the shared InotifyTracker if not already running
|
||||||
once.Do(goRun)
|
once.Do(goRun)
|
||||||
|
|
||||||
|
shared.mux.Lock()
|
||||||
|
done := shared.done[fname]
|
||||||
|
if done != nil {
|
||||||
|
delete(shared.done, fname)
|
||||||
|
close(done)
|
||||||
|
}
|
||||||
|
shared.mux.Unlock()
|
||||||
|
|
||||||
shared.remove <- fname
|
shared.remove <- fname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +107,7 @@ func (shared *InotifyTracker) watchFlags(fname string, flags uint32) error {
|
||||||
|
|
||||||
if shared.chans[fname] == nil {
|
if shared.chans[fname] == nil {
|
||||||
shared.chans[fname] = make(chan *fsnotify.FileEvent)
|
shared.chans[fname] = make(chan *fsnotify.FileEvent)
|
||||||
|
shared.done[fname] = make(chan bool)
|
||||||
}
|
}
|
||||||
return shared.watcher.WatchFlags(fname, flags)
|
return shared.watcher.WatchFlags(fname, flags)
|
||||||
}
|
}
|
||||||
|
@ -117,11 +128,15 @@ func (shared *InotifyTracker) removeWatch(fname string) {
|
||||||
|
|
||||||
// sendEvent sends the input event to the appropriate Tail.
|
// sendEvent sends the input event to the appropriate Tail.
|
||||||
func (shared *InotifyTracker) sendEvent(event *fsnotify.FileEvent) {
|
func (shared *InotifyTracker) sendEvent(event *fsnotify.FileEvent) {
|
||||||
ch := shared.Events(event.Name)
|
shared.mux.Lock()
|
||||||
if ch != nil {
|
ch := shared.chans[event.Name]
|
||||||
|
done := shared.done[event.Name]
|
||||||
|
shared.mux.Unlock()
|
||||||
|
|
||||||
|
if ch != nil && done != nil {
|
||||||
select {
|
select {
|
||||||
case ch <- event:
|
case ch <- event:
|
||||||
default:
|
case <-done:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue