etcdserver/api/v2v3: fix "getDir" with "sorted"

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-05-09 13:42:37 -07:00
parent 26e46702a2
commit ba7cc04bac

View File

@ -18,6 +18,7 @@ import (
"context"
"fmt"
"path"
"sort"
"strings"
"time"
@ -94,6 +95,9 @@ func (s *v2v3Store) Get(nodePath string, recursive, sorted bool) (*v2store.Event
func (s *v2v3Store) getDir(nodePath string, recursive, sorted bool, rev int64) ([]*v2store.NodeExtern, error) {
rootNodes, err := s.getDirDepth(nodePath, 1, rev)
if err != nil || !recursive {
if sorted {
sort.Sort(v2store.NodeExterns(rootNodes))
}
return rootNodes, err
}
nextNodes := rootNodes
@ -110,6 +114,10 @@ func (s *v2v3Store) getDir(nodePath string, recursive, sorted bool, rev int64) (
return nil, err
}
}
if sorted {
sort.Sort(v2store.NodeExterns(rootNodes))
}
return rootNodes, nil
}