runtime/internal/rpc: Remove support for the old glob interfaces

MultiPart: 1/2
Change-Id: Ia7d4ce6d410f8cd72aee2a58180db34c172b20b2
diff --git a/runtime/internal/rpc/reserved.go b/runtime/internal/rpc/reserved.go
index 2f63127..c82aaa0 100644
--- a/runtime/internal/rpc/reserved.go
+++ b/runtime/internal/rpc/reserved.go
@@ -278,65 +278,14 @@
 			}
 			continue
 		}
+		if gs.AllGlobberX != nil {
+			gs.AllGlobber = gs.AllGlobberX
+		}
+		if gs.ChildrenGlobberX != nil {
+			gs.ChildrenGlobber = gs.ChildrenGlobberX
+		}
 		if gs.AllGlobber != nil {
 			ctx.VI(3).Infof("rpc Glob: %q implements AllGlobber", suffix)
-			ch, err := gs.AllGlobber.Glob__(ctx, subcall, state.glob.String())
-			if err != nil {
-				ctx.VI(3).Infof("rpc Glob: %q.Glob(%q) failed: %v", suffix, state.glob, err)
-				subcall.Send(naming.GlobReplyError{naming.GlobError{Name: state.name, Error: verror.Convert(verror.ErrInternal, ctx, err)}})
-				continue
-			}
-			if ch == nil {
-				continue
-			}
-			for gr := range ch {
-				switch v := gr.(type) {
-				case naming.GlobReplyEntry:
-					v.Value.Name = naming.Join(state.name, v.Value.Name)
-					subcall.Send(v)
-				case naming.GlobReplyError:
-					v.Value.Name = naming.Join(state.name, v.Value.Name)
-					subcall.Send(v)
-				}
-			}
-			continue
-		}
-		if gs.ChildrenGlobber != nil {
-			ctx.VI(3).Infof("rpc Glob: %q implements ChildrenGlobber", suffix)
-			children, err := gs.ChildrenGlobber.GlobChildren__(ctx, subcall)
-			// The requested object doesn't exist.
-			if err != nil {
-				subcall.Send(naming.GlobReplyError{naming.GlobError{Name: state.name, Error: verror.Convert(verror.ErrInternal, ctx, err)}})
-				continue
-			}
-			// The glob pattern matches the current object.
-			if state.glob.Len() == 0 {
-				subcall.Send(naming.GlobReplyEntry{naming.MountEntry{Name: state.name}})
-			}
-			// The current object has no children.
-			if children == nil {
-				continue
-			}
-			depth := state.depth
-			// This is a recursive pattern. Make sure we don't recurse forever.
-			if state.glob.Len() == 0 {
-				depth++
-			}
-			matcher, left := state.glob.Head(), state.glob.Tail()
-			for child := range children {
-				if len(child) == 0 || strings.Contains(child, "/") {
-					ctx.Errorf("rpc Glob: %q.GlobChildren__() sent an invalid child name: %q", suffix, child)
-					continue
-				}
-				if matcher.Match(child) {
-					next := naming.Join(state.name, child)
-					queue = append(queue, gState{next, left, depth})
-				}
-			}
-			continue
-		}
-		if gs.AllGlobberX != nil {
-			ctx.VI(3).Infof("rpc Glob: %q implements AllGlobberX", suffix)
 			send := func(reply naming.GlobReply) error {
 				select {
 				case <-ctx.Done():
@@ -353,14 +302,14 @@
 				}
 				return nil
 			}
-			if err := gs.AllGlobberX.Glob__(ctx, &globServerCall{subcall, send}, state.glob); err != nil {
+			if err := gs.AllGlobber.Glob__(ctx, &globServerCall{subcall, send}, state.glob); err != nil {
 				ctx.VI(3).Infof("rpc Glob: %q.Glob(%q) failed: %v", suffix, state.glob, err)
 				subcall.Send(naming.GlobReplyError{naming.GlobError{Name: state.name, Error: verror.Convert(verror.ErrInternal, ctx, err)}})
 			}
 			continue
 		}
-		if gs.ChildrenGlobberX != nil {
-			ctx.VI(3).Infof("rpc Glob: %q implements ChildrenGlobberX", suffix)
+		if gs.ChildrenGlobber != nil {
+			ctx.VI(3).Infof("rpc Glob: %q implements ChildrenGlobber", suffix)
 			depth := state.depth
 			if state.glob.Len() == 0 {
 				// The glob pattern matches the current object.
@@ -397,7 +346,7 @@
 				}
 				return nil
 			}
-			if err := gs.ChildrenGlobberX.GlobChildren__(ctx, &globChildrenServerCall{subcall, send}, matcher); err != nil {
+			if err := gs.ChildrenGlobber.GlobChildren__(ctx, &globChildrenServerCall{subcall, send}, matcher); err != nil {
 				subcall.Send(naming.GlobReplyError{naming.GlobError{Name: state.name, Error: verror.Convert(verror.ErrInternal, ctx, err)}})
 			}
 			continue
diff --git a/runtime/internal/rpc/test/glob_test.go b/runtime/internal/rpc/test/glob_test.go
index d16e4bd..a60f0d4 100644
--- a/runtime/internal/rpc/test/glob_test.go
+++ b/runtime/internal/rpc/test/glob_test.go
@@ -35,7 +35,6 @@
 		"a/b/c2/d1",
 		"a/b/c2/d2",
 		"a/x/y/z",
-		"a/X/y/z",
 		"leaf",
 	}
 	tree := newNode()
@@ -63,9 +62,6 @@
 		{"", "...", []string{
 			"",
 			"a",
-			"a/X",
-			"a/X/y",
-			"a/X/y/z",
 			"a/b",
 			"a/b/c1",
 			"a/b/c1/d1",
@@ -80,9 +76,6 @@
 		}, nil},
 		{"a", "...", []string{
 			"",
-			"X",
-			"X/y",
-			"X/y/z",
 			"b",
 			"b/c1",
 			"b/c1/d1",
@@ -123,15 +116,10 @@
 		{"a/x/y/z", "...", []string{
 			"",
 		}, nil},
-		{"a/X", "...", []string{
-			"",
-			"y",
-			"y/z",
-		}, nil},
 		{"", "", []string{""}, nil},
 		{"", "*", []string{"a", "leaf"}, nil},
 		{"a", "", []string{""}, nil},
-		{"a", "*", []string{"X", "b", "x"}, nil},
+		{"a", "*", []string{"b", "x"}, nil},
 		{"a/b", "", []string{""}, nil},
 		{"a/b", "*", []string{"c1", "c2"}, nil},
 		{"a/b/c1", "", []string{""}, nil},
@@ -143,8 +131,8 @@
 		{"a/b/c2/d1", "*", []string{}, nil},
 		{"a/b/c2/d1", "", []string{""}, nil},
 		{"a", "*/c?", []string{"b/c1", "b/c2"}, nil},
-		{"a", "*/*", []string{"X/y", "b/c1", "b/c2", "x/y"}, nil},
-		{"a", "*/*/*", []string{"X/y/z", "b/c1/d1", "b/c1/d2", "b/c2/d1", "b/c2/d2", "x/y/z"}, nil},
+		{"a", "*/*", []string{"b/c1", "b/c2", "x/y"}, nil},
+		{"a", "*/*/*", []string{"b/c1/d1", "b/c1/d2", "b/c2/d1", "b/c2/d2", "x/y/z"}, nil},
 		{"a/x", "*/*", []string{"y/z"}, nil},
 		{"bad", "", []string{}, []naming.GlobError{{Name: "", Error: noExist}}},
 		{"bad/foo", "", []string{}, []naming.GlobError{{Name: "", Error: noExist}}},
@@ -266,13 +254,12 @@
 	tree *node
 }
 
-func (d *disp) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) {
+func (d *disp) Lookup(ctx *context.T, suffix string) (interface{}, security.Authorizer, error) {
 	elems := strings.Split(suffix, "/")
 	var auth security.Authorizer
 	for _, e := range elems {
 		if e == "deny" {
-			auth = &denyAllAuthorizer{}
-			break
+			return &leafObject{}, &denyAllAuthorizer{}, nil
 		}
 	}
 	if len(elems) != 0 && elems[0] == "muah" {
@@ -281,18 +268,16 @@
 
 	}
 	if len(elems) != 0 && elems[len(elems)-1] == "leaf" {
-		return leafObject{}, auth, nil
+		return &leafObject{}, auth, nil
+	}
+	n := d.tree.find(elems, false)
+	if n == nil {
+		return nil, nil, verror.New(verror.ErrNoExist, ctx, suffix)
 	}
 	if len(elems) < 2 || (elems[0] == "a" && elems[1] == "x") {
-		return &vChildrenObject{d.tree, elems}, auth, nil
+		return &vChildrenObject{n}, auth, nil
 	}
-	if len(elems) < 2 || (elems[0] == "a" && elems[1] == "X") {
-		return &vChildrenXObject{d.tree, elems}, auth, nil
-	}
-	if len(elems) >= 3 && elems[0] == "a" && elems[1] == "b" && elems[2] == "c2" {
-		return &globXObject{d.tree, elems}, auth, nil
-	}
-	return &globObject{d.tree, elems}, auth, nil
+	return &globObject{n}, auth, nil
 }
 
 type denyAllAuthorizer struct{}
@@ -302,75 +287,15 @@
 }
 
 type globObject struct {
-	n      *node
-	suffix []string
+	n *node
 }
 
-func (o *globObject) Glob__(ctx *context.T, _ rpc.ServerCall, pattern string) (<-chan naming.GlobReply, error) {
-	g, err := glob.Parse(pattern)
-	if err != nil {
-		return nil, err
-	}
-	n := o.n.find(o.suffix, false)
-	if n == nil {
-		return nil, verror.New(verror.ErrNoExist, ctx, o.suffix)
-	}
-	ch := make(chan naming.GlobReply)
-	go func() {
-		o.globLoop(ch, "", g, n)
-		close(ch)
-	}()
-	return ch, nil
-}
-
-func (o *globObject) globLoop(ch chan<- naming.GlobReply, name string, g *glob.Glob, n *node) {
-	if g.Len() == 0 {
-		ch <- naming.GlobReplyEntry{naming.MountEntry{Name: name}}
-	}
-	if g.Empty() {
-		return
-	}
-	matcher, left := g.Head(), g.Tail()
-	for leaf, child := range n.children {
-		if matcher.Match(leaf) {
-			o.globLoop(ch, naming.Join(name, leaf), left, child)
-		}
-	}
-}
-
-type vChildrenObject struct {
-	n      *node
-	suffix []string
-}
-
-func (o *vChildrenObject) GlobChildren__(ctx *context.T, _ rpc.ServerCall) (<-chan string, error) {
-	n := o.n.find(o.suffix, false)
-	if n == nil {
-		return nil, verror.New(verror.ErrNoExist, ctx, o.suffix)
-	}
-	ch := make(chan string, len(n.children))
-	for child, _ := range n.children {
-		ch <- child
-	}
-	close(ch)
-	return ch, nil
-}
-
-type globXObject struct {
-	n      *node
-	suffix []string
-}
-
-func (o *globXObject) Glob__(ctx *context.T, call rpc.GlobServerCall, g *glob.Glob) error {
-	n := o.n.find(o.suffix, false)
-	if n == nil {
-		return verror.New(verror.ErrNoExist, ctx, o.suffix)
-	}
-	o.globLoop(call, "", g, n)
+func (o *globObject) Glob__(ctx *context.T, call rpc.GlobServerCall, g *glob.Glob) error {
+	o.globLoop(call, "", g, o.n)
 	return nil
 }
 
-func (o *globXObject) globLoop(call rpc.GlobServerCall, name string, g *glob.Glob, n *node) {
+func (o *globObject) globLoop(call rpc.GlobServerCall, name string, g *glob.Glob, n *node) {
 	if g.Len() == 0 {
 		call.SendStream().Send(naming.GlobReplyEntry{naming.MountEntry{Name: name}})
 	}
@@ -385,18 +310,13 @@
 	}
 }
 
-type vChildrenXObject struct {
-	n      *node
-	suffix []string
+type vChildrenObject struct {
+	n *node
 }
 
-func (o *vChildrenXObject) GlobChildren__(ctx *context.T, call rpc.GlobChildrenServerCall, m *glob.Element) error {
-	n := o.n.find(o.suffix, false)
-	if n == nil {
-		return verror.New(verror.ErrNoExist, ctx, o.suffix)
-	}
+func (o *vChildrenObject) GlobChildren__(ctx *context.T, call rpc.GlobChildrenServerCall, m *glob.Element) error {
 	sender := call.SendStream()
-	for child, _ := range n.children {
+	for child, _ := range o.n.children {
 		if m.Match(child) {
 			sender.Send(naming.GlobChildrenReplyName{child})
 		}
@@ -438,6 +358,6 @@
 
 type leafObject struct{}
 
-func (l leafObject) Func(*context.T, rpc.ServerCall) error {
+func (leafObject) Func(*context.T, rpc.ServerCall) error {
 	return nil
 }
diff --git a/services/binary/tidy/binaryd/mock.go b/services/binary/tidy/binaryd/mock.go
index 5e9daf0..a9c1db0 100644
--- a/services/binary/tidy/binaryd/mock.go
+++ b/services/binary/tidy/binaryd/mock.go
@@ -9,6 +9,7 @@
 	"testing"
 
 	"v.io/v23/context"
+	"v.io/v23/glob"
 	"v.io/v23/naming"
 	"v.io/v23/rpc"
 	"v.io/v23/security"
@@ -69,15 +70,13 @@
 	Err     error
 }
 
-func (mdi *MockBinarydInvoker) Glob__(p *context.T, _ rpc.ServerCall, pattern string) (<-chan naming.GlobReply, error) {
-	gs := GlobStimulus{pattern}
+func (mdi *MockBinarydInvoker) Glob__(p *context.T, call rpc.GlobServerCall, g *glob.Glob) error {
+	gs := GlobStimulus{g.String()}
 	gr := mdi.Tape.Record(gs).(GlobResponse)
-	ch := make(chan naming.GlobReply, len(gr.Results))
-	defer close(ch)
 	for _, r := range gr.Results {
-		ch <- naming.GlobReplyEntry{naming.MountEntry{Name: r}}
+		call.SendStream().Send(naming.GlobReplyEntry{naming.MountEntry{Name: r}})
 	}
-	return ch, gr.Err
+	return gr.Err
 }
 
 type dispatcher struct {