Skip to content

Commit

Permalink
kqueue: don't change internal state when Add() returns error (#638)
Browse files Browse the repository at this point in the history
Fixes #637
  • Loading branch information
arp242 committed May 16, 2024
1 parent ad74244 commit 800ed83
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions backend_fen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func TestRemoveState(t *testing.T) {

check(1, 1)

// Shouldn't change internal state.
if err := w.Add("/path-doesnt-exist"); err == nil {
t.Fatal(err)
}
check(1, 1)

if err := w.Remove(file); err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions backend_inotify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func TestRemoveState(t *testing.T) {

check(2)

// Shouldn't change internal state.
if err := w.Add("/path-doesnt-exist"); err == nil {
t.Fatal(err)
}
check(2)

if err := w.Remove(file); err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 5 additions & 2 deletions backend_kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,12 @@ func (w *kqueue) AddWith(name string, opts ...addOpt) error {
return fmt.Errorf("%w: %s", xErrUnsupported, with.op)
}

w.watches.addUserWatch(name)
_, err := w.addWatch(name, noteAllEvents)
return err
if err != nil {
return err
}
w.watches.addUserWatch(name)
return nil
}

func (w *kqueue) Remove(name string) error {
Expand Down
6 changes: 6 additions & 0 deletions backend_kqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func TestRemoveState(t *testing.T) {

check(2, 3)

// Shouldn't change internal state.
if err := w.Add("/path-doesnt-exist"); err == nil {
t.Fatal(err)
}
check(2, 3)

if err := w.Remove(file); err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions backend_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func TestRemoveState(t *testing.T) {

check(2)

// Shouldn't change internal state.
if err := w.Add("/path-doesnt-exist"); err == nil {
t.Fatal(err)
}
check(2)

if err := w.Remove(file); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 800ed83

Please sign in to comment.