From 3ae0a1e1a6874f2749855e02411a15016c7c4df6 Mon Sep 17 00:00:00 2001 From: Sam Ghods Date: Thu, 17 Apr 2014 15:05:14 -0700 Subject: [PATCH] fix(store.go) include node.dir = true when updating a directory's ttl, fixes coreos/etcd#736 --- store/store.go | 10 +++++++--- store/store_test.go | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/store/store.go b/store/store.go index 25ab54894..5a5c3ba2f 100644 --- a/store/store.go +++ b/store/store.go @@ -432,9 +432,13 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) ( n.Write(newValue, nextIndex) - // copy the value for safety - newValueCopy := ustrings.Clone(newValue) - eNode.Value = &newValueCopy + if n.IsDir() { + eNode.Dir = true + } else { + // copy the value for safety + newValueCopy := ustrings.Clone(newValue) + eNode.Value = &newValueCopy + } // update ttl n.UpdateTTL(expireTime) diff --git a/store/store_test.go b/store/store_test.go index 157b9053d..ddd9afbee 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -287,8 +287,9 @@ func TestStoreUpdateDirTTL(t *testing.T) { s.Create("/foo", true, "", false, Permanent) s.Create("/foo/bar", false, "baz", false, Permanent) - _, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond)) - e, _ := s.Get("/foo/bar", false, false) + e, err := s.Update("/foo", "", time.Now().Add(500*time.Millisecond)) + assert.Equal(t, e.Node.Dir, true, "") + e, _ = s.Get("/foo/bar", false, false) assert.Equal(t, *e.Node.Value, "baz", "") time.Sleep(600 * time.Millisecond)