Skip to content

Commit

Permalink
Use the already implemented traverse functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fr123k committed Sep 14, 2021
1 parent cf457b0 commit df65bf5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
8 changes: 3 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,17 @@ func (client *Client) List(absolutePath string) (result []string, err error) {
if client.isTopLevelPath(absolutePath) {
result = client.listTopLevel()
} else {
result, err = client.listLowLevel(normalizedVaultPath(absolutePath), MODE_DIRECTORY_ONLY)
result, err = client.listLowLevel(normalizedVaultPath(absolutePath))
}
return result, err
}

// List elements at the given absolutePath, using the given client
func (client *Client) ListAll(absolutePath string) (result []string, err error) {
if client.isTopLevelPath(absolutePath) {
result, err = client.listAllFromTopLevel()
result = client.topLevelTraverse()
} else {
res:= []string{}
result, err = client.listAllLowLevel(normalizedVaultPath(absolutePath), &res)
result = res
result = client.lowLevelTraverse(normalizedVaultPath(absolutePath), false)
}
return result, err
}
Expand Down
39 changes: 2 additions & 37 deletions client/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@ import (
"github.com/fishi0x01/vsh/log"
)

const (
MODE_IGNORE_NONE_DIRECTORY = 0
MODE_DIRECTORY_ONLY = 1
)

func (client *Client) listTopLevel() (result []string) {
for k := range client.KVBackends {
result = append(result, k)
}
return result
}

func (client *Client) listLowLevel(path string, mode int) (result []string, err error) {
func (client *Client) listLowLevel(path string) (result []string, err error) {
t := client.lowLevelType(path)
if t != BACKEND && t != NODE {
if mode == MODE_DIRECTORY_ONLY {
return nil, errors.New("Not a directory: " + path)
} else if mode == MODE_IGNORE_NONE_DIRECTORY {
return nil, nil
}
return nil, errors.New("Not a directory: " + path)
}

s, err := client.cache.List(client.getKVMetaDataPath(path))
Expand All @@ -46,29 +37,3 @@ func (client *Client) listLowLevel(path string, mode int) (result []string, err

return result, err
}

func (client *Client) listAllLowLevel(path string, subResult* []string) (result[]string, err error) {
subResult2, err := client.listLowLevel(path, MODE_IGNORE_NONE_DIRECTORY)
if subResult2 != nil {
var subResult3 []string
for _, resultPath := range subResult2 {
_, err := client.listAllLowLevel(normalizedVaultPath(path + resultPath), subResult)
if err != nil {
log.AppTrace("%+v", err)
return subResult3, err
}
result = append(result, normalizedVaultPath(path + resultPath))
}
} else {
*subResult = append(*subResult, path)
}
return *subResult, err
}

func (client *Client) listAllFromTopLevel() (result []string, err error) {
res:= []string{}
for k := range client.KVBackends {
result, err = client.listAllLowLevel(normalizedVaultPath(k), &res)
}
return result, err
}

0 comments on commit df65bf5

Please sign in to comment.