Skip to content

Commit

Permalink
store: Add IsKeyDir
Browse files Browse the repository at this point in the history
IsKeyDir is needed so we can check if a given key is a directory. This
should be a public method because we need to check whether a request
includes Dir=true in etcdserver.

Addressed issue etcd-io#518 on github.
  • Loading branch information
iankronquist committed Jan 25, 2015
1 parent 056fae8 commit 28fad9c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
type Store interface {
Version() int
Index() uint64
IsKeyDir(nodePath string) bool

Get(nodePath string, recursive, sorted bool) (*Event, error)
Set(nodePath string, dir bool, value string, expireTime time.Time) (*Event, error)
Expand Down Expand Up @@ -100,6 +101,17 @@ func (s *store) Index() uint64 {
return s.CurrentIndex
}

func (s *store) IsKeyDir(nodePath string) bool {
node, _ := s.internalGet(nodePath)
// If there is an error, then either the path does not exist or it is not
// a dir. Either way, it is not a dir, so return false
if node != nil {
return node.IsDir()
} else {
return false
}
}

// Get returns a get event.
// If recursive is true, it will return all the content under the node path.
// If sorted is true, it will sort the content by keys.
Expand Down

0 comments on commit 28fad9c

Please sign in to comment.