You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ra...@apache.org on 2012/03/23 14:06:51 UTC

[2/2] git commit: Revert "create the system dbs straight away"

Revert "create the system dbs straight away"

We can't do this. Turns out we actually either specify that we wish to
overwrite the file or we fail couch_file:open even when create is
specified. Seems a bit crazy to me.

This reverts commit 5e2e0bb5a8dfce77e74340de74790ba87195434a.


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

Branch: refs/heads/1.1.x
Commit: 5c8940cecd75b66d2f7357549d6ee9d49a8094bb
Parents: 5e2e0bb
Author: Randall Leeds <ra...@apache.org>
Authored: Fri Mar 23 06:02:06 2012 -0700
Committer: Randall Leeds <ra...@apache.org>
Committed: Fri Mar 23 06:02:06 2012 -0700

----------------------------------------------------------------------
 src/couchdb/couch_auth_cache.erl          |   22 ++++++++++++----------
 src/couchdb/couch_replication_manager.erl |    8 ++++++--
 2 files changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/5c8940ce/src/couchdb/couch_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_auth_cache.erl b/src/couchdb/couch_auth_cache.erl
index d5a61ea..e0715b8 100644
--- a/src/couchdb/couch_auth_cache.erl
+++ b/src/couchdb/couch_auth_cache.erl
@@ -367,7 +367,7 @@ exec_if_auth_db(Fun, DefRes) ->
 
 open_auth_db() ->
     [{auth_db_name, DbName}] = ets:lookup(?STATE, auth_db_name),
-    {ok, AuthDb} = ensure_users_db_exists(DbName),
+    {ok, AuthDb} = ensure_users_db_exists(DbName, [sys_db]),
     AuthDb.
 
 
@@ -388,15 +388,17 @@ get_user_props_from_db(UserName) ->
         nil
     ).
 
-ensure_users_db_exists(DbName) ->
-    Options1 = [
-        create,
-        {user_ctx, #user_ctx{roles=[<<"_admin">>]}},
-        sys_db
-    ],
-    {ok, Db} = couch_db:open(DbName, Options1),
-    ok = ensure_auth_ddoc_exists(Db, <<"_design/_auth">>),
-    {ok, Db}.
+ensure_users_db_exists(DbName, Options) ->
+    Options1 = [{user_ctx, #user_ctx{roles=[<<"_admin">>]}} | Options],
+    case couch_db:open(DbName, Options1) of
+    {ok, Db} ->
+        ensure_auth_ddoc_exists(Db, <<"_design/_auth">>),
+        {ok, Db};
+    _Error ->
+        {ok, Db} = couch_db:create(DbName, Options1),
+        ok = ensure_auth_ddoc_exists(Db, <<"_design/_auth">>),
+        {ok, Db}
+    end.
 
 ensure_auth_ddoc_exists(Db, DDocId) ->
     case couch_db:open_doc(Db, DDocId) of

http://git-wip-us.apache.org/repos/asf/couchdb/blob/5c8940ce/src/couchdb/couch_replication_manager.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_replication_manager.erl b/src/couchdb/couch_replication_manager.erl
index 1e4f04c..b3c6db1 100644
--- a/src/couchdb/couch_replication_manager.erl
+++ b/src/couchdb/couch_replication_manager.erl
@@ -565,11 +565,15 @@ zone(Hr, Min) ->
 ensure_rep_db_exists() ->
     DbName = ?l2b(couch_config:get("replicator", "db", "_replicator")),
     Opts = [
-        create,
         {user_ctx, #user_ctx{roles=[<<"_admin">>, <<"_replicator">>]}},
         sys_db
     ],
-    {ok, Db} = couch_db:open(DbName, Opts),
+    case couch_db:open(DbName, Opts) of
+    {ok, Db} ->
+        Db;
+    _Error ->
+        {ok, Db} = couch_db:create(DbName, Opts)
+    end,
     ok = ensure_rep_ddoc_exists(Db, <<"_design/_replicator">>),
     {ok, Db}.