Browse Source

fix can change the value of a dir bug

Xiang Li 12 years ago
parent
commit
9dc51d0412
4 changed files with 13 additions and 1 deletions
  1. 6 0
      client_handlers.go
  2. 1 0
      error.go
  3. 3 1
      store/store.go
  4. 3 0
      store/tree.go

+ 6 - 0
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

+ 1 - 0
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"

+ 3 - 1
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)

+ 3 - 0
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
 	}