From 433face91a4e994f02b0193dce10d75fc83be86d Mon Sep 17 00:00:00 2001 From: Pawel Knap Date: Tue, 10 Feb 2015 15:21:56 +0100 Subject: [PATCH] readdcw: add support for recursive <-> non-recursive rewatching (fixes #66) --- sync_readdcw_test.go | 8 ++++++++ sync_unix_test.go | 5 +++++ testing_test.go | 2 ++ watcher_readdcw.go | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sync_readdcw_test.go b/sync_readdcw_test.go index a43b051..7a93fcb 100644 --- a/sync_readdcw_test.go +++ b/sync_readdcw_test.go @@ -7,6 +7,7 @@ package notify import ( "syscall" + "time" "unsafe" ) @@ -23,3 +24,10 @@ func Sync() { // dbg.Print("SetSystemFileCacheSize error:", err) // } } + +// UpdateWait pauses the program for some minimal amount of time. This function +// is required only by implementations which work asynchronously. It gives +// watcher structure time to update its internal state. +func UpdateWait() { + time.Sleep(50 * time.Millisecond) +} diff --git a/sync_unix_test.go b/sync_unix_test.go index a7b997c..854cc49 100644 --- a/sync_unix_test.go +++ b/sync_unix_test.go @@ -11,3 +11,8 @@ import "syscall" func Sync() { syscall.Sync() } + +// UpdateWait is required only by windows watcher implementation. On other +// platforms this function is no-op. +func UpdateWait() { +} diff --git a/testing_test.go b/testing_test.go index f819d00..0e5783c 100644 --- a/testing_test.go +++ b/testing_test.go @@ -431,6 +431,7 @@ func drainall(c chan EventInfo) (ei []EventInfo) { // ExpectAny TODO func (w *W) ExpectAny(cases []WCase) { + UpdateWait() // Wait some time before starting the test. Test: for i, cas := range cases { dbg.Printf("ExpectAny: i=%d\n", i) @@ -825,6 +826,7 @@ func (n *N) ExpectTreeEvents(cases []TCase, all Chans) { // ExpectNotifyEvents TODO(rjeczalik) func (n *N) ExpectNotifyEvents(cases []NCase, all Chans) { + UpdateWait() // Wait some time before starting the test. for i, cas := range cases { dbg.Printf("ExpectNotifyEvents: i=%d\n", i) cas.Event.Action() diff --git a/watcher_readdcw.go b/watcher_readdcw.go index 20295d7..bf61826 100644 --- a/watcher_readdcw.go +++ b/watcher_readdcw.go @@ -426,7 +426,7 @@ func (r *readdcw) RecursiveRewatch(oldpath, newpath string, oldevent, return err } return r.watch(newpath, newevent, true) - case oldevent != newevent: + default: return r.rewatch(newpath, uint32(oldevent), uint32(newevent), true) } return nil