You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2012/01/25 08:20:54 UTC

[2/4] git commit: Prevent multiple updates to a single _local doc

Prevent multiple updates to a single _local doc

If a user uploads a two _local docs with the same docid in a _bulk_docs
request the updater will insert multiple entries into the local docs
btree. This patch avoids that by throwing an error if a user attempts
it.

This is an old bug that I caught and just added a fix for. I split it
out as its own patch to point out that its a bug fix that differs from
the old behvior.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/9d0db1b9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/9d0db1b9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/9d0db1b9

Branch: refs/heads/new-security-object
Commit: 9d0db1b923dba01b665674dc55ada47a4fe6146c
Parents: eb4138f
Author: Paul Joseph Davis <da...@apache.org>
Authored: Mon Jan 23 17:56:18 2012 -0600
Committer: Paul Joseph Davis <da...@apache.org>
Committed: Wed Jan 25 01:14:07 2012 -0600

----------------------------------------------------------------------
 src/couchdb/couch_db.erl |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/9d0db1b9/src/couchdb/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl
index a6903c4..be65f53 100644
--- a/src/couchdb/couch_db.erl
+++ b/src/couchdb/couch_db.erl
@@ -727,6 +727,16 @@ update_docs(Db, Docs, Options, interactive_edit) ->
             end
         end, {[], []}, Docs2),
 
+    % Prevent updating multiple _local docs in a single update
+    % request. This relies on couch_db_updater not collecting
+    % more than one update that contains _local docs but this
+    % is still trigerable with a _bulk_docs request.
+    UniqNRIds = lists:usort([Id || #doc{id=Id} <- NonRepDocs0]),
+    case length(UniqNRIds) == length(NonRepDocs0) of
+        true -> ok;
+        false -> throw({update_error, repeated_local_docs})
+    end,
+
     {NonRepDocs, _} = new_revs(NonRepDocs0, [], []),
 
     DocBuckets = before_docs_update(Db, group_alike_docs(Docs3)),