mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #538 from xiangli-cmu/fix_hidden_watch
fix(watcher_hub)
This commit is contained in:
commit
68305181f9
@ -161,6 +161,11 @@ func (wh *watcherHub) clone() *watcherHub {
|
|||||||
// isHidden checks to see if key path is considered hidden to watch path i.e. the
|
// isHidden checks to see if key path is considered hidden to watch path i.e. the
|
||||||
// last element is hidden or it's within a hidden directory
|
// last element is hidden or it's within a hidden directory
|
||||||
func isHidden(watchPath, keyPath string) bool {
|
func isHidden(watchPath, keyPath string) bool {
|
||||||
|
// When deleting a directory, watchPath might be deeper than the actual keyPath
|
||||||
|
// For example, when deleting /foo we also need to notify watchers on /foo/bar.
|
||||||
|
if len(watchPath) > len(keyPath) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
// if watch path is just a "/", after path will start without "/"
|
// if watch path is just a "/", after path will start without "/"
|
||||||
// add a "/" to deal with the special case when watchPath is "/"
|
// add a "/" to deal with the special case when watchPath is "/"
|
||||||
afterPath := path.Clean("/" + keyPath[len(watchPath):])
|
afterPath := path.Clean("/" + keyPath[len(watchPath):])
|
||||||
|
@ -40,4 +40,13 @@ func TestIsHidden(t *testing.T) {
|
|||||||
if !hidden {
|
if !hidden {
|
||||||
t.Fatalf("%v should be hidden to %v\n", key, watch)
|
t.Fatalf("%v should be hidden to %v\n", key, watch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// watch at "/_foo/foo"
|
||||||
|
// key is "/_foo"
|
||||||
|
watch = "_foo/foo"
|
||||||
|
key = "/_foo/"
|
||||||
|
hidden = isHidden(watch, key)
|
||||||
|
if hidden {
|
||||||
|
t.Fatalf("%v should not be hidden to %v\n", key, watch)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user