Browse Source

Revert "Merge pull request #631 from metaflow/fix-delete-key-as-directory"

This reverts commit b87972713e17fb815bfe42f25a63f94f232007e2, reversing
changes made to bd8d45ce28d6f9ddb9c5164f58aca8f9a6359f7b.
Yicheng Qin 11 years ago
parent
commit
fa54866e99
3 changed files with 2 additions and 57 deletions
  1. 1 1
      error/error.go
  2. 1 52
      server/v2/tests/delete_handler_test.go
  3. 0 4
      store/store.go

+ 1 - 1
error/error.go

@@ -131,7 +131,7 @@ func (e Error) Write(w http.ResponseWriter) {
 	switch e.ErrorCode {
 	switch e.ErrorCode {
 	case EcodeKeyNotFound:
 	case EcodeKeyNotFound:
 		status = http.StatusNotFound
 		status = http.StatusNotFound
-	case EcodeNotFile, EcodeDirNotEmpty, EcodeNotDir:
+	case EcodeNotFile, EcodeDirNotEmpty:
 		status = http.StatusForbidden
 		status = http.StatusForbidden
 	case EcodeTestFailed, EcodeNodeExist:
 	case EcodeTestFailed, EcodeNodeExist:
 		status = http.StatusPreconditionFailed
 		status = http.StatusPreconditionFailed

+ 1 - 52
server/v2/tests/delete_handler_test.go

@@ -30,30 +30,6 @@ func TestV2DeleteKey(t *testing.T) {
 	})
 	})
 }
 }
 
 
-// Ensures that a key is deleted when 'dir' is not specified or false
-//
-//   $ curl -X PUT localhost:4001/v2/keys/foo/bar -d value=XXX
-//   $ curl -X DELETE localhost:4001/v2/keys/foo/bar?dir=true -> fail
-//   $ curl -X DELETE localhost:4001/v2/keys/foo/bar?dir=false
-//
-func TestV2DeleteKeyAsDirectory(t *testing.T) {
-	tests.RunServer(func(s *server.Server) {
-		v := url.Values{}
-		v.Set("value", "XXX")
-		resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar"), v)
-		tests.ReadBody(resp)
-		resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar?dir=true"), url.Values{})
-		assert.Equal(t, resp.StatusCode, http.StatusForbidden)
-		bodyJson := tests.ReadBodyJSON(resp)
-		assert.Equal(t, bodyJson["errorCode"], 104, "")
-		resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar?dir=false"), url.Values{})
-		assert.Equal(t, resp.StatusCode, http.StatusOK)
-		body := tests.ReadBody(resp)
-		assert.Nil(t, err, "")
-		assert.Equal(t, string(body), `{"action":"delete","node":{"key":"/foo/bar","modifiedIndex":3,"createdIndex":2},"prevNode":{"key":"/foo/bar","value":"XXX","modifiedIndex":2,"createdIndex":2}}`, "")
-	})
-}
-
 // Ensures that an empty directory is deleted when dir is set.
 // Ensures that an empty directory is deleted when dir is set.
 //
 //
 //   $ curl -X PUT localhost:4001/v2/keys/foo?dir=true
 //   $ curl -X PUT localhost:4001/v2/keys/foo?dir=true
@@ -76,7 +52,7 @@ func TestV2DeleteEmptyDirectory(t *testing.T) {
 	})
 	})
 }
 }
 
 
-// Ensures that a not-empty directory is deleted when dir and recursive is set.
+// Ensures that a not-empty directory is deleted when dir is set.
 //
 //
 //   $ curl -X PUT localhost:4001/v2/keys/foo/bar?dir=true
 //   $ curl -X PUT localhost:4001/v2/keys/foo/bar?dir=true
 //   $ curl -X DELETE localhost:4001/v2/keys/foo?dir=true ->fail
 //   $ curl -X DELETE localhost:4001/v2/keys/foo?dir=true ->fail
@@ -115,33 +91,6 @@ func TestV2DeleteDirectoryRecursiveImpliesDir(t *testing.T) {
 	})
 	})
 }
 }
 
 
-// Ensures that prevIndex / prevValue are invalid for for directory deletion
-//
-//   $ curl -X PUT localhost:4001/v2/keys/foo?dir=true
-//   $ curl -X DELETE localhost:4001/v2/keys/foo?prevValue=X -> fail
-//   $ curl -X DELETE localhost:4001/v2/keys/foo?prevIndex=0 -> fail
-//   $ curl -X DELETE localhost:4001/v2/keys/foo?dir=true
-//
-func TestV2DeleteDirectoryRejectPrevArguments(t *testing.T) {
-	tests.RunServer(func(s *server.Server) {
-		resp, err := tests.PutForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo?dir=true"), url.Values{})
-		tests.ReadBody(resp)
-		resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo?prevValue=X"), url.Values{})
-		assert.Equal(t, resp.StatusCode, http.StatusForbidden)
-		bodyJson := tests.ReadBodyJSON(resp)
-		assert.Equal(t, bodyJson["errorCode"], 102, "")
-		resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo?prevIndex=0"), url.Values{})
-		assert.Equal(t, resp.StatusCode, http.StatusForbidden)
-		bodyJson = tests.ReadBodyJSON(resp)
-		assert.Equal(t, bodyJson["errorCode"], 102, "")
-		resp, err = tests.DeleteForm(fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo?dir=true"), url.Values{})
-		assert.Equal(t, resp.StatusCode, http.StatusOK)
-		body := tests.ReadBody(resp)
-		assert.Nil(t, err, "")
-		assert.Equal(t, string(body), `{"action":"delete","node":{"key":"/foo","dir":true,"modifiedIndex":3,"createdIndex":2},"prevNode":{"key":"/foo","dir":true,"modifiedIndex":2,"createdIndex":2}}`, "")
-	})
-}
-
 // Ensures that a key is deleted if the previous index matches
 // Ensures that a key is deleted if the previous index matches
 //
 //
 //   $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX
 //   $ curl -X PUT localhost:4001/v2/keys/foo -d value=XXX

+ 0 - 4
store/store.go

@@ -280,10 +280,6 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
 
 
 	if n.IsDir() {
 	if n.IsDir() {
 		eNode.Dir = true
 		eNode.Dir = true
-	} else {
-		if dir {
-			return nil, etcdErr.NewError(etcdErr.EcodeNotDir, n.Path, s.Index())
-		}
 	}
 	}
 
 
 	callback := func(path string) { // notify function
 	callback := func(path string) { // notify function