couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Hendricks <mich...@ndrix.org>
Subject [PATCH] _bulk_docs: Make deleting a deleted document a conflict
Date Thu, 10 Jul 2008 23:33:42 GMT
When using the REST API, if one tries to delete a document which
has already been deleted, he receives a 404 error.  However, if
one tries the same thing with the _bulk_docs API, the deletion
is accepted without error.  This patch causes _bulk_docs to generate
a 412 error if one attempts to delete a document which has already
been deleted.

Signed-off-by: Michael Hendricks <michael@ndrix.org>
---
 share/www/script/couch_tests.js |   10 ++++++++++
 src/couchdb/couch_db.erl        |    4 +++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index 6a1e72c..7c8af78 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -223,6 +223,16 @@ var tests = {
     T(result.new_revs.length == 5);
     for (i = 0; i < 5; i++) {
       T(db.open(docs[i]._id) == null);
+      docs[i]._deleted = true;
+    }
+
+    // Deleting the docs again fails
+    try {
+      db.bulkSave(docs);
+      T("no double delete conflict" && false); // we shouldn't hit here
+    } catch (e) {
+      T(e.error == "conflict");
+      T(e.reason == "Update conflict");
     }
   },
 
diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl
index 05b584a..f8330ed 100644
--- a/src/couchdb/couch_db.erl
+++ b/src/couchdb/couch_db.erl
@@ -238,6 +238,8 @@ prepare_doc_for_new_edit(Db, #doc{id=Id,revs=[NewRev|PrevRevs]}=Doc, OldFullDocI
     case PrevRevs of
     [PrevRev|_] ->
         case dict:find(PrevRev, LeafRevsDict) of
+        {ok, {true, Sp, DiskRevs}} ->
+            throw(conflict);
         {ok, {Deleted, Sp, DiskRevs}} ->
             case couch_doc:has_stubs(Doc) of
             true ->
@@ -1035,4 +1037,4 @@ start_copy_compact_int(#db{name=Name,filepath=Filepath}=Db, CopyLocal)
->
     Db#db.update_pid ! {compact_done, CompactFile}.
     
     
-    
\ No newline at end of file
+    
-- 
1.5.6


Mime
View raw message