From afd80c034cac3fd3e99628eaf9d30f53f82e3866 Mon Sep 17 00:00:00 2001 From: presbrey Date: Fri, 20 Sep 2013 12:47:55 -0400 Subject: [PATCH] fix race/panic on modify+delete This fixes a race condition when a file is modified and unlinked in the OS before the inotify IsModify event has a chance to call os.Stat. --- watch/inotify.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/watch/inotify.go b/watch/inotify.go index 7cab0fd..d7368e7 100644 --- a/watch/inotify.go +++ b/watch/inotify.go @@ -97,6 +97,10 @@ func (fw *InotifyFileWatcher) ChangeEvents(t tomb.Tomb, fi os.FileInfo) *FileCha case evt.IsModify(): fi, err := os.Stat(fw.Filename) if err != nil { + if os.IsNotExist(err) { + changes.NotifyDeleted() + return + } // XXX: no panic here panic(err) }