From 36be402e66319ac387bf9555b43f5ab845eeefa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Thu, 11 Jul 2024 15:31:50 +0200 Subject: [PATCH] Add a flag to the events indicating whether the subject is a directory --- inotifywaitgo/models.go | 4 ++++ inotifywaitgo/watcher.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/inotifywaitgo/models.go b/inotifywaitgo/models.go index 9eaf896..48701fc 100644 --- a/inotifywaitgo/models.go +++ b/inotifywaitgo/models.go @@ -59,6 +59,9 @@ const ( EventDeleteSelf = "delete_self" // The filesystem on which a watched file or directory resides was unmounted. After this event the file or directory is no longer being watched. Note that this event can occur even if it is not explicitly being listened to. EventUnmount = "unmount" + + // The subject of this event is a directory + FlagIsdir = "ISDIR" ) type EVENT int @@ -84,6 +87,7 @@ const ( type FileEvent struct { Filename string Events []EVENT + IsDir bool } var EVENT_MAP = map[int]string{ diff --git a/inotifywaitgo/watcher.go b/inotifywaitgo/watcher.go index b953744..6529331 100644 --- a/inotifywaitgo/watcher.go +++ b/inotifywaitgo/watcher.go @@ -75,8 +75,14 @@ func WatchPath(s *Settings) { } } var eventsEvents []EVENT + isDir := false for _, eventStr := range eventsStr { + if eventStr == FlagIsdir { + isDir = true + continue + } + eventStr = strings.ToLower(eventStr) event, ok := EVENT_MAP_REVERSE[eventStr] if !ok { @@ -89,6 +95,7 @@ func WatchPath(s *Settings) { event := FileEvent{ Filename: prefix + file, Events: eventsEvents, + IsDir: isDir, } // Send the file name to the channel