Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #87 from heyitsanthony/fix-get-root
Browse files Browse the repository at this point in the history
zketcd: don't crash on getting root directory
  • Loading branch information
xiang90 authored Nov 3, 2017
2 parents 34ef3e1 + 7fd93fe commit ffbe4da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ var (
acl = zk.WorldACL(zk.PermAll)
)

func TestGetRoot(t *testing.T) {
runTest(t, func(t *testing.T, c *zk.Conn) {
if _, _, err := c.Get("/"); err != nil {
t.Fatal(err)
}
})
}

func TestDirStat(t *testing.T) {
runTest(t, func(t *testing.T, c *zk.Conn) {
if _, err := c.Create("/abc", []byte(""), 0, acl); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion zketcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ func (z *zkEtcd) GetData(xid Xid, op *GetDataRequest) ZKResponse {
}
z.s.Watch(zxid, xid, p, EventNodeDataChanged, f)
}
datResp.Data = []byte(txnresp.Responses[2].GetResponseRange().Kvs[0].Value)

// Root directory has no data.
if p != rootPath {
datResp.Data = []byte(txnresp.Responses[2].GetResponseRange().Kvs[0].Value)
}

glog.V(7).Infof("GetData(%v) = (zxid=%v, resp=%+v)", xid, zxid, *datResp)
return mkZKResp(xid, zxid, datResp)
Expand Down

0 comments on commit ffbe4da

Please sign in to comment.