You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Michael Hendricks <mi...@ndrix.org> on 2008/07/11 01:33:42 UTC
[PATCH] _bulk_docs: Make deleting a deleted document a conflict
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 <mi...@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