couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch-replicator commit: updated refs/heads/master to 8629fb2
Date Thu, 09 Jun 2016 18:56:40 GMT
Repository: couchdb-couch-replicator
Updated Branches:
  refs/heads/master 869744113 -> 8629fb269


Ensure _design/_replicator VDU is updated


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/8629fb26
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/8629fb26
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/8629fb26

Branch: refs/heads/master
Commit: 8629fb2690e4d11ecc0ad15ef032d3f109a93285
Parents: 8697441
Author: Robert Newson <rnewson@apache.org>
Authored: Thu Jun 9 15:39:04 2016 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Jun 9 19:56:29 2016 +0100

----------------------------------------------------------------------
 src/couch_replicator_manager.erl | 49 +++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/8629fb26/src/couch_replicator_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_manager.erl b/src/couch_replicator_manager.erl
index 342dffb..21d732f 100644
--- a/src/couch_replicator_manager.erl
+++ b/src/couch_replicator_manager.erl
@@ -795,23 +795,40 @@ ensure_rep_ddoc_exists(RepDb) ->
 
 ensure_rep_ddoc_exists(RepDb, DDocId) ->
     case open_rep_doc(RepDb, DDocId) of
-        {ok, _Doc} ->
-            ok;
-        _ ->
-            DDoc = couch_doc:from_json_obj({[
-                {<<"_id">>, DDocId},
-                {<<"language">>, <<"javascript">>},
-                {<<"validate_doc_update">>, ?REP_DB_DOC_VALIDATE_FUN}
-            ]}),
-            try
-                {ok, _} = save_rep_doc(RepDb, DDoc)
-            catch
-                throw:conflict ->
-                    % NFC what to do about this other than
-                    % not kill the process.
-                    ok
+        {not_found, _Reason} ->
+            {ok, DDoc} = replication_design_doc(DDocId),
+            couch_log:notice("creating replicator ddoc", []),
+            {ok, _Rev} = save_rep_doc(RepDb, DDoc);
+        {ok, Doc} ->
+            {Props} = couch_doc:to_json_obj(Doc, []),
+            case couch_util:get_value(<<"validate_doc_update">>, Props, []) of
+                ?REP_DB_DOC_VALIDATE_FUN ->
+                    ok;
+                _ ->
+                    Props1 = lists:keyreplace(<<"validate_doc_update">>, 1, Props,
+                         {<<"validate_doc_update">>,
+                        ?REP_DB_DOC_VALIDATE_FUN}),
+                    DDoc = couch_doc:from_json_obj({Props1}),
+                    couch_log:notice("updating replicator ddoc", []),
+                    try
+                        {ok, _} = save_rep_doc(RepDb, DDoc)
+                    catch
+                        throw:conflict ->
+                            %% ignore, we'll retry next time
+                            ok
+                    end
             end
-    end.
+    end,
+    ok.
+
+replication_design_doc(DDocId) ->
+    DocProps = [
+        {<<"_id">>, DDocId},
+        {<<"language">>, <<"javascript">>},
+        {<<"validate_doc_update">>, ?REP_DB_DOC_VALIDATE_FUN}
+   ],
+   {ok, couch_doc:from_json_obj({DocProps})}.
+
 
 % pretty-print replication id
 pp_rep_id(#rep{id = RepId}) ->


Mime
View raw message