veyron/runtimes/google/naming/namespace: Allow Glob with rooted pattern
This change makes it possible to use Glob() with a rooted pattern, e.g.
Glob("/host:port/*").
Change-Id: I4657b25d2398515ad12eddd5c12c7a06098e5507
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index 3925350..e921c39 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -383,6 +383,13 @@
for _, test := range globTests {
out := doGlob(t, r, ns, test.pattern)
compare(t, "Glob", test.pattern, test.expected, out)
+ // Do the same with a full rooted name.
+ out = doGlob(t, r, ns, naming.JoinAddressName(root.name, test.pattern))
+ var expectedWithRoot []string
+ for _, s := range test.expected {
+ expectedWithRoot = append(expectedWithRoot, naming.JoinAddressName(root.name, s))
+ }
+ compare(t, "Glob", test.pattern, expectedWithRoot, out)
}
}
diff --git a/runtimes/google/naming/namespace/glob.go b/runtimes/google/naming/namespace/glob.go
index e6071a8..2560bfb 100644
--- a/runtimes/google/naming/namespace/glob.go
+++ b/runtimes/google/naming/namespace/glob.go
@@ -80,7 +80,8 @@
// Glob implements naming.MountTable.Glob.
func (ns *namespace) Glob(ctx context.T, pattern string) (chan naming.MountEntry, error) {
- g, err := glob.Parse(pattern)
+ root, globPattern := naming.SplitAddressName(pattern)
+ g, err := glob.Parse(globPattern)
if err != nil {
return nil, err
}
@@ -90,6 +91,9 @@
var prefixElements []string
prefixElements, g = g.SplitFixedPrefix()
prefix := strings.Join(prefixElements, "/")
+ if len(root) != 0 {
+ prefix = naming.JoinAddressName(root, prefix)
+ }
// Start a thread to get the results and return the reply channel to the caller.
servers := ns.rootName(prefix)