From 4ba7d85d561e857bac8cf8e5a706c352b13aa723 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 5 Dec 2013 17:16:44 -0500 Subject: [PATCH] refactor(update) more clear dir checking --- store/store.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/store/store.go b/store/store.go index 026737b76..88b512447 100644 --- a/store/store.go +++ b/store/store.go @@ -366,23 +366,16 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) ( e := newEvent(Update, nodePath, nextIndex, n.CreatedIndex) eNode := e.Node - if len(newValue) != 0 { - if n.IsDir() { - // if the node is a directory, we cannot update value - s.Stats.Inc(UpdateFail) - return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex) - } - - eNode.PrevValue = n.Value - n.Write(newValue, nextIndex) - eNode.Value = newValue - - } else { - // update value to empty - eNode.Value = n.Value - n.Value = "" + if n.IsDir() && len(newValue) != 0 { + // if the node is a directory, we cannot update value to non-empty + s.Stats.Inc(UpdateFail) + return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex) } + eNode.PrevValue = n.Value + n.Write(newValue, nextIndex) + eNode.Value = newValue + // update ttl n.UpdateTTL(expireTime)