/
glob_children.go
50 lines (46 loc) · 1.57 KB
/
glob_children.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package util
import (
"v.io/v23/context"
"v.io/v23/glob"
"v.io/v23/naming"
"v.io/v23/rpc"
pubutil "v.io/v23/syncbase/util"
"v.io/v23/verror"
"v.io/x/ref/services/syncbase/common"
"v.io/x/ref/services/syncbase/store"
)
// Note, Syncbase handles Glob requests by implementing GlobChildren__ at each
// level (service, database, collection).
// GlobChildren implements glob over the Syncbase namespace.
func GlobChildren(ctx *context.T, call rpc.GlobChildrenServerCall, matcher *glob.Element, sntx store.SnapshotOrTransaction, stKeyPrefix string) error {
encPrefix, _ := matcher.FixedPrefix()
prefix, err := pubutil.Decode(encPrefix)
if err != nil {
return verror.New(verror.ErrBadArg, ctx, err)
}
it := sntx.Scan(common.ScanPrefixArgs(stKeyPrefix, prefix))
key := []byte{}
for it.Advance() {
key = it.Key(key)
parts := common.SplitKeyParts(string(key))
id, err := common.DecodeIdKeyPart(parts[len(parts)-1])
if err != nil {
return verror.New(verror.ErrBadState, ctx, err)
}
encId := pubutil.EncodeId(id)
if matcher.Match(encId) {
// TODO(rogulenko): Check for resolve access. (For collection glob, this
// means checking prefix perms.)
if err := call.SendStream().Send(naming.GlobChildrenReplyName{Value: encId}); err != nil {
return err
}
}
}
if err := it.Err(); err != nil {
call.SendStream().Send(naming.GlobChildrenReplyError{Value: naming.GlobError{Error: err}})
}
return nil
}