From 3ca1edc9ed334bc382f0eea45453dde177fa4a29 Mon Sep 17 00:00:00 2001 From: Arun Mathew Date: Mon, 1 Aug 2016 15:47:06 +0900 Subject: [PATCH 1/2] Issue 98 Buffered channels to avoid lost NotifyDeleted()/NotifyTruncated()/NotifyModified() signals --- watch/filechanges.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watch/filechanges.go b/watch/filechanges.go index 3ce5dce..f80aead 100644 --- a/watch/filechanges.go +++ b/watch/filechanges.go @@ -8,7 +8,7 @@ type FileChanges struct { func NewFileChanges() *FileChanges { return &FileChanges{ - make(chan bool), make(chan bool), make(chan bool)} + make(chan bool, 1), make(chan bool, 1), make(chan bool, 1)} } func (fc *FileChanges) NotifyModified() { From 48cd00098ff201df71e04b99a6cf6f20c25b51ff Mon Sep 17 00:00:00 2001 From: Arun Mathew Date: Mon, 1 Aug 2016 15:48:42 +0900 Subject: [PATCH 2/2] Issue 97 Fixing deferred RemoveWatch() due to which tailing stops (gets stuck) in certain conditions --- watch/inotify.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/watch/inotify.go b/watch/inotify.go index 4478f1e..408a68d 100644 --- a/watch/inotify.go +++ b/watch/inotify.go @@ -75,7 +75,6 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange fw.Size = pos go func() { - defer RemoveWatch(fw.Filename) events := Events(fw.Filename) @@ -88,9 +87,11 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange select { case evt, ok = <-events: if !ok { + RemoveWatch(fw.Filename) return } case <-t.Dying(): + RemoveWatch(fw.Filename) return } @@ -99,6 +100,7 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange fallthrough case evt.Op&fsnotify.Rename == fsnotify.Rename: + RemoveWatch(fw.Filename) changes.NotifyDeleted() return @@ -106,6 +108,7 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange fi, err := os.Stat(fw.Filename) if err != nil { if os.IsNotExist(err) { + RemoveWatch(fw.Filename) changes.NotifyDeleted() return }