Browse Source

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

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee 7 years ago
parent
commit
ba7cc04bac
1 changed files with 8 additions and 0 deletions
  1. 8 0
      etcdserver/api/v2v3/store.go

+ 8 - 0
etcdserver/api/v2v3/store.go

@@ -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
 }