Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle inotify isdir flag #5

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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