Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4351FCCE2 for ; Fri, 12 Dec 2014 02:15:20 +0000 (UTC) Received: (qmail 65210 invoked by uid 500); 12 Dec 2014 02:15:20 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 65162 invoked by uid 500); 12 Dec 2014 02:15:20 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 65153 invoked by uid 99); 12 Dec 2014 02:15:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Dec 2014 02:15:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9C96AA27DF3; Fri, 12 Dec 2014 02:15:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davisp@apache.org To: commits@couchdb.apache.org Message-Id: <62b44dbe21224d09af2168f5bc5bd276@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: fabric commit: updated refs/heads/2510-add-system-db-handlers to 4e0e81f Date: Fri, 12 Dec 2014 02:15:19 +0000 (UTC) Repository: couchdb-fabric Updated Branches: refs/heads/2510-add-system-db-handlers [created] 4e0e81fd9 Add system db handlers to fabric_doc_update This hard codes the before_doc_write functions for replicator and user databases like they are in couch_server. This is mostly motivated by the fact that couch_users_db:before_doc_update/1 adds random salt values to user documents when a password is changed. The replicator databases are included at this level for consistency with couch_server. COUCHDB-2510 Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/4e0e81fd Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/4e0e81fd Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/4e0e81fd Branch: refs/heads/2510-add-system-db-handlers Commit: 4e0e81fd9d668bf4d532864b9cab3ad2d7653d50 Parents: 5930256 Author: Paul J. Davis Authored: Thu Dec 11 20:13:57 2014 -0600 Committer: Paul J. Davis Committed: Thu Dec 11 20:13:57 2014 -0600 ---------------------------------------------------------------------- src/fabric_doc_update.erl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/4e0e81fd/src/fabric_doc_update.erl ---------------------------------------------------------------------- diff --git a/src/fabric_doc_update.erl b/src/fabric_doc_update.erl index f593b12..4febe13 100644 --- a/src/fabric_doc_update.erl +++ b/src/fabric_doc_update.erl @@ -21,7 +21,8 @@ go(_, [], _) -> {ok, []}; go(DbName, AllDocs0, Opts) -> - AllDocs = tag_docs(AllDocs0), + AllDocs1 = before_doc_update(DbName, AllDocs0), + AllDocs = tag_docs(AllDocs1), validate_atomic_update(DbName, AllDocs, lists:member(all_or_nothing, Opts)), Options = lists:delete(all_or_nothing, Opts), GroupedDocs = lists:map(fun({#shard{name=Name, node=Node} = Shard, Docs}) -> @@ -97,6 +98,28 @@ handle_message({not_found, no_db_file} = X, Worker, Acc0) -> handle_message({bad_request, Msg}, _, _) -> throw({bad_request, Msg}). +before_doc_update(DbName, Docs) -> + case {is_replicator_db(DbName), is_users_db(DbName)} of + {true, _} -> + lists:map(fun couch_replicator_manager:before_doc_update/1, Docs); + {_, true} -> + lists:map(fun couch_users_db:before_doc_update/1, Docs); + _ -> + Docs + end. + +is_replicator_db(DbName) -> + ConfigName = list_to_binary(config:get("replicator", "db", "_replicator")), + DbName == ConfigName orelse path_ends_with(DbName, <<"_replicator">>). + +is_users_db(DbName) -> + ConfigName = list_to_binary(config:get( + "couch_httpd_auth", "authentication_db", "_users")), + DbName == ConfigName orelse path_ends_with(DbName, <<"_users">>). + +path_ends_with(Path, Suffix) -> + Suffix == lists:last(binary:split(mem3:dbname(Path), <<"/">>, [global])). + tag_docs([]) -> []; tag_docs([#doc{meta=Meta}=Doc | Rest]) ->