Skip to content

Commit

Permalink
Add a flag to the events indicating whether the subject is a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jul 11, 2024
1 parent f54c624 commit 36be402
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inotifywaitgo/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -84,6 +87,7 @@ const (
type FileEvent struct {
Filename string
Events []EVENT
IsDir bool
}

var EVENT_MAP = map[int]string{
Expand Down
7 changes: 7 additions & 0 deletions inotifywaitgo/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -89,6 +95,7 @@ func WatchPath(s *Settings) {
event := FileEvent{
Filename: prefix + file,
Events: eventsEvents,
IsDir: isDir,
}

// Send the file name to the channel
Expand Down

0 comments on commit 36be402

Please sign in to comment.