From 34f2c19dc6cfe91bcf70a2e4e8ef64020bd8e3c7 Mon Sep 17 00:00:00 2001 From: horahoradev Date: Sat, 23 Jul 2022 15:51:29 -0700 Subject: [PATCH] Added ignoreLinux lstats back in --- inotify.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/inotify.go b/inotify.go index 02570f11..a42da583 100644 --- a/inotify.go +++ b/inotify.go @@ -297,7 +297,21 @@ func (w *Watcher) readEvents() { // channel. Such as events marked ignore by the kernel, or MODIFY events // against files that do not exist. func (e *Event) ignoreLinux(mask uint32) bool { - return mask&unix.IN_IGNORED == unix.IN_IGNORED + // Ignore anything the inotify API says to ignore + if mask&unix.IN_IGNORED == unix.IN_IGNORED { + return true + } + + // If the event is Create or Write, the file must exist, or the + // event will be suppressed. + // *Note*: this was put in place because it was seen that a Write + // event was sent after the Remove. This ignores the Write and + // assumes a Remove will come or has come if the file doesn't exist. + if e.Op&Create == Create || e.Op&Write == Write { + _, statErr := os.Lstat(e.Name) + return os.IsNotExist(statErr) + } + return false } // newEvent returns an platform-independent Event based on an inotify mask.