Skip to content

Commit ee4bfd4

Browse files
committed
Add Or API to event actions
- caller can specify/chain operations
1 parent 562780d commit ee4bfd4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

fanotify_api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,8 @@ func (l *Listener) ClearWatch() error {
180180
func (actions Action) Has(a Action) bool {
181181
return actions&a == a
182182
}
183+
184+
// Or appends the specified action to the set of actions to watch for
185+
func (actions Action) Or(a Action) Action {
186+
return actions | a
187+
}

fanotify_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,11 @@ func TestWithCapSysAdmFanotifyFileOrDirDeleted(t *testing.T) {
373373
assert.True(t, event.Actions.Has(FileDeleted))
374374
}
375375
}
376+
377+
func TestActions(t *testing.T) {
378+
var actions Action
379+
actions = FileCreated.Or(FileModified.Or(FileDeleted))
380+
assert.True(t, actions.Has(FileCreated))
381+
assert.True(t, actions.Has(FileModified))
382+
assert.True(t, actions.Has(FileDeleted))
383+
}

0 commit comments

Comments
 (0)