* [bugfix] close handle when remWatch open in getIno
* Use new tests
Note: the tests pass even without the syscall.CloseHandle()
Co-authored-by: jie <jie@tt.com>
Co-authored-by: Martin Tournoij <martin@arp242.net>
})
}
+// TODO: should also check internal state is correct/cleaned up; e.g. no
+// left-over file descriptors or whatnot.
func TestRemove(t *testing.T) {
t.Run("works", func(t *testing.T) {
t.Parallel()
}
})
+ t.Run("remove same dir twice", func(t *testing.T) {
+ tmp := t.TempDir()
+
+ touch(t, tmp, "file")
+
+ w := newWatcher(t)
+ defer w.Close()
+
+ addWatch(t, w, tmp)
+
+ if err := w.Remove(tmp); err != nil {
+ t.Fatal(err)
+ }
+ if err := w.Remove(tmp); err == nil {
+ t.Fatal("no error")
+ }
+ })
+
// Make sure that concurrent calls to Remove() don't race.
t.Run("no race", func(t *testing.T) {
t.Parallel()
w.mu.Lock()
watch := w.watches.get(ino)
w.mu.Unlock()
+ if err := syscall.CloseHandle(ino.handle); err != nil {
+ w.Errors <- os.NewSyscallError("CloseHandle", err)
+ }
if watch == nil {
return fmt.Errorf("%w: %s", ErrNonExistentWatch, pathname)
}