Return-Path: Delivered-To: apmail-incubator-couchdb-dev-archive@locus.apache.org Received: (qmail 58848 invoked from network); 10 Jul 2008 23:34:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Jul 2008 23:34:22 -0000 Received: (qmail 84825 invoked by uid 500); 10 Jul 2008 23:34:22 -0000 Delivered-To: apmail-incubator-couchdb-dev-archive@incubator.apache.org Received: (qmail 84782 invoked by uid 500); 10 Jul 2008 23:34:22 -0000 Mailing-List: contact couchdb-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-dev@incubator.apache.org Received: (qmail 84771 invoked by uid 99); 10 Jul 2008 23:34:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2008 16:34:22 -0700 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [66.111.4.27] (HELO out3.smtp.messagingengine.com) (66.111.4.27) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2008 23:33:29 +0000 Received: from compute2.internal (compute2.internal [10.202.2.42]) by out1.messagingengine.com (Postfix) with ESMTP id 3AB78139941 for ; Thu, 10 Jul 2008 19:33:50 -0400 (EDT) Received: from heartbeat2.messagingengine.com ([10.202.2.161]) by compute2.internal (MEProxy); Thu, 10 Jul 2008 19:33:50 -0400 X-Sasl-enc: kewEJA2uZ/LLSAQcwwZM59r/lcVZg+DaCZy3HmoWjvPP 1215732828 Received: from ndrix.org (tameion.ndrix.org [166.230.131.80]) by mail.messagingengine.com (Postfix) with ESMTPSA id A07F92B7A0; Thu, 10 Jul 2008 19:33:48 -0400 (EDT) From: Michael Hendricks To: couchdb-dev@incubator.apache.org Cc: Michael Hendricks Subject: [PATCH] _bulk_docs: Make deleting a deleted document a conflict Date: Thu, 10 Jul 2008 17:33:42 -0600 Message-Id: <1215732822-17692-1-git-send-email-michael@ndrix.org> X-Mailer: git-send-email 1.5.6 In-Reply-To: <20080710033453.GA4875@ginosko.ndrix.org> References: <20080710033453.GA4875@ginosko.ndrix.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 --- 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