-
Notifications
You must be signed in to change notification settings - Fork 12
/
traverse.go
45 lines (40 loc) · 1.02 KB
/
traverse.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
package client
import (
"github.com/fishi0x01/vsh/log"
"strings"
)
func (client *Client) topLevelTraverse() (result []string) {
for k := range client.KVBackends {
result = append(result, k)
}
return result
}
func (client *Client) lowLevelTraverse(path string, shallow bool) (result []string) {
s, err := client.cache.List(client.getKVMetaDataPath(path))
if err != nil {
log.AppTrace("%+v", err)
return
}
if s != nil {
if keysInterface, ok := s.Data["keys"]; ok {
for _, valInterface := range keysInterface.([]interface{}) {
val := valInterface.(string)
// prevent ambiguous dir/file to be added twice
if strings.HasSuffix(val, "/") {
// dir
if shallow == false {
result = append(result, client.lowLevelTraverse(path+"/"+val, false)...)
}
} else {
// file
leaf := strings.ReplaceAll("/"+path+"/"+val, "//", "/")
result = append(result, leaf)
}
}
}
} else {
leaf := strings.ReplaceAll("/"+path, "//", "/")
result = append(result, leaf)
}
return result
}