From df65bf52ffc5082c11e540e32ca9703f97601baf Mon Sep 17 00:00:00 2001 From: Frank Ittermann Date: Tue, 14 Sep 2021 13:49:45 +0200 Subject: [PATCH] Use the already implemented traverse functions --- client/client.go | 8 +++----- client/list.go | 39 ++------------------------------------- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/client/client.go b/client/client.go index 32b4a1a8..748cf258 100644 --- a/client/client.go +++ b/client/client.go @@ -137,7 +137,7 @@ 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 } @@ -145,11 +145,9 @@ func (client *Client) List(absolutePath string) (result []string, err error) { // 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 } diff --git a/client/list.go b/client/list.go index dfc7b919..96f0e8c5 100644 --- a/client/list.go +++ b/client/list.go @@ -7,11 +7,6 @@ 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) @@ -19,14 +14,10 @@ func (client *Client) listTopLevel() (result []string) { 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)) @@ -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 -} \ No newline at end of file