From 9dc51d0412f55e567e0a2aeba87bcb4f4e453fb3 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Fri, 12 Jul 2013 16:36:21 -0700 Subject: [PATCH] fix can change the value of a dir bug --- client_handlers.go | 6 ++++++ error.go | 1 + store/store.go | 4 +++- store/tree.go | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/client_handlers.go b/client_handlers.go index 83b2bc954..8b8e0b1ce 100644 --- a/client_handlers.go +++ b/client_handlers.go @@ -135,6 +135,12 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool) (*w).Write(newJsonError(101, err.Error())) return } + + if _, ok := err.(store.NotFile); ok { + (*w).WriteHeader(http.StatusBadRequest) + (*w).Write(newJsonError(102, err.Error())) + return + } (*w).WriteHeader(http.StatusInternalServerError) (*w).Write(newJsonError(300, "No Leader")) return diff --git a/error.go b/error.go index 4de0c7494..9c17c244c 100644 --- a/error.go +++ b/error.go @@ -12,6 +12,7 @@ func init() { // command related errors errors[100] = "Key Not Found" errors[101] = "The given PrevValue is not equal to the value of the key" + errors[102] = "Not A File" // Post form related errors errors[200] = "Value is Required in POST form" errors[201] = "PrevValue is Required in POST form" diff --git a/store/store.go b/store/store.go index 1b0efe3b9..fe27b0b23 100644 --- a/store/store.go +++ b/store/store.go @@ -242,6 +242,7 @@ func (s *Store) Set(key string, value string, expireTime time.Time, index uint64 s.addToResponseMap(index, &resp) return msg, err } + } // Get the value of the key and return the raw response @@ -351,12 +352,13 @@ func (s *Store) Delete(key string, index uint64) ([]byte, error) { s.Tree.delete(key) + } else { resp.Expiration = &node.ExpireTime // Kill the expire go routine node.update <- PERMANENT s.Tree.delete(key) - + } msg, err := json.Marshal(resp) diff --git a/store/tree.go b/store/tree.go index 25e8795ed..5a3a8b0e0 100644 --- a/store/tree.go +++ b/store/tree.go @@ -104,6 +104,9 @@ func (t *tree) set(key string, value Node) bool { nodeMap[nodesName[i]] = tn } else { + if tn.Dir { + return false + } // we change the value of a old Treenode tn.InternalNode = value }