FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
exp/inotify: cleanup ignored watch

inotify sends the IN_IGNORED event whenever a watch was removed.
Fixes issue 2483

Please review this at http://codereview.appspot.com/6553059/

Affected files:
M src/pkg/exp/inotify/inotify_linux.go
M src/pkg/exp/inotify/inotify_linux_test.go


Index: src/pkg/exp/inotify/inotify_linux.go
===================================================================
--- a/src/pkg/exp/inotify/inotify_linux.go
+++ b/src/pkg/exp/inotify/inotify_linux.go
@@ -196,6 +196,11 @@
// the "paths" map.
w.mu.Lock()
event.Name = w.paths[int(raw.Wd)]
+ // Remove stale watch
+ if event.Mask&IN_IGNORED != 0 {
+ delete(w.watches, event.Name)
+ delete(w.paths, int(raw.Wd))
+ }
w.mu.Unlock()
if nameLen > 0 {
// Point "bytes" at the first byte of the filename
Index: src/pkg/exp/inotify/inotify_linux_test.go
===================================================================
--- a/src/pkg/exp/inotify/inotify_linux_test.go
+++ b/src/pkg/exp/inotify/inotify_linux_test.go
@@ -105,3 +105,34 @@
t.Fatal("expected error on Watch() after Close(), got nil")
}
}
+func TestInotifyIgnored(t *testing.T) {
+ watcher, err := NewWatcher()
+ if err != nil {
+ t.Fatalf("NewWatcher failed: %s", err)
+ }
+
+ dir, err := ioutil.TempDir("", "inotify")
+ if err != nil {
+ t.Fatalf("TempDir failed: %s", err)
+ }
+ err = watcher.Watch(dir)
+ if err != nil {
+ t.Fatalf("Watch failed: %s", err)
+ }
+ go func() {
+ for err := range watcher.Error {
+ t.Fatalf("error received: %s", err)
+ }
+ }()
+ go func() {
+ for event := range watcher.Event {
+ t.Logf("event received: %s", event)
+ }
+ }()
+ os.Remove(dir)
+ time.Sleep(50 * time.Millisecond)
+ _, ok := watcher.watches[dir]
+ if ok {
+ t.Fatal("expected removed watch")
+ }
+}

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 3 | next ›
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 23, '12 at 6:42p
activeSep 28, '12 at 2:16a
posts3
users2
websitegolang.org

2 users in discussion

Dave: 2 posts Mbnull Org: 1 post

People

Translate

site design / logo © 2022 Grokbase