fix can change the value of a dir bug

This commit is contained in:
Xiang Li
2013-07-12 16:36:21 -07:00
parent bff9321aa2
commit 9dc51d0412
4 changed files with 13 additions and 1 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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)

View File

@@ -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
}