forked from vitessio/vitess
/
directory.go
46 lines (39 loc) · 1006 Bytes
/
directory.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
package etcdtopo
import (
"path"
"github.com/youtube/vitess/go/vt/topo"
"golang.org/x/net/context"
)
func (s *Server) clientForCell(cell string) (Client, error) {
if cell == topo.GlobalCell {
return s.getGlobal(), nil
}
cc, err := s.getCell(cell)
if err != nil {
return nil, err
}
return cc.Client, nil
}
// ListDir is part of the topo.Backend interface.
func (s *Server) ListDir(ctx context.Context, cell, dirPath string) ([]string, error) {
c, err := s.clientForCell(cell)
if err != nil {
return nil, err
}
// clean all extra '/' before getting the contents.
dirPath = path.Clean(dirPath)
resp, err := c.Get(dirPath, true /* sort */, false /* recursive */)
if err != nil {
return nil, convertError(err)
}
var names []string
for _, n := range resp.Node.Nodes {
base := path.Base(n.Key)
// we have to remove /vt from global listings, it is used for /vt/cells.
if dirPath == "/" && base == "vt" {
continue
}
names = append(names, base)
}
return names, nil
}