refactor(update) more clear dir checking

This commit is contained in:
Xiang Li 2013-12-05 17:16:44 -05:00
parent 40d297be66
commit 4ba7d85d56

View File

@ -366,9 +366,8 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (
e := newEvent(Update, nodePath, nextIndex, n.CreatedIndex) e := newEvent(Update, nodePath, nextIndex, n.CreatedIndex)
eNode := e.Node eNode := e.Node
if len(newValue) != 0 { if n.IsDir() && len(newValue) != 0 {
if n.IsDir() { // if the node is a directory, we cannot update value to non-empty
// if the node is a directory, we cannot update value
s.Stats.Inc(UpdateFail) s.Stats.Inc(UpdateFail)
return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex) return nil, etcdErr.NewError(etcdErr.EcodeNotFile, nodePath, currIndex)
} }
@ -377,12 +376,6 @@ func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (
n.Write(newValue, nextIndex) n.Write(newValue, nextIndex)
eNode.Value = newValue eNode.Value = newValue
} else {
// update value to empty
eNode.Value = n.Value
n.Value = ""
}
// update ttl // update ttl
n.UpdateTTL(expireTime) n.UpdateTTL(expireTime)