You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/08/12 17:54:13 UTC
[13/13] couch commit: updated refs/heads/master to 311ba94
Add couch_db_plugin:on_delete/2
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/311ba943
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/311ba943
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/311ba943
Branch: refs/heads/master
Commit: 311ba943c3e6af2a2a3ce1c6d8905918b32f9618
Parents: b387a0b
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Aug 11 13:38:01 2015 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Aug 11 13:38:01 2015 -0700
----------------------------------------------------------------------
src/couch_db_plugin.erl | 8 +++++++-
src/couch_server.erl | 2 ++
test/couch_db_plugin_tests.erl | 28 ++++++++++++++++++++++++++--
3 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/311ba943/src/couch_db_plugin.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_plugin.erl b/src/couch_db_plugin.erl
index cac078a..1e05c77 100644
--- a/src/couch_db_plugin.erl
+++ b/src/couch_db_plugin.erl
@@ -17,7 +17,8 @@
before_doc_update/2,
after_doc_read/2,
validate_docid/1,
- check_is_admin/1
+ check_is_admin/1,
+ on_delete/2
]).
-define(SERVICE_ID, couch_db).
@@ -56,6 +57,11 @@ check_is_admin(Db) ->
%% callbacks return true only if it specifically allow the given Id
couch_epi:any(Handle, ?SERVICE_ID, check_is_admin, [Db], [ignore_providers]).
+on_delete(DbName, Options) ->
+ Handle = couch_epi:get_handle(?SERVICE_ID),
+ couch_epi:apply(Handle, ?SERVICE_ID, on_delete, [DbName, Options],
+ [ignore_providers]).
+
%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/311ba943/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index 93b6f5f..e1ee3de 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -458,6 +458,8 @@ handle_call({delete, DbName, Options}, _From, Server) ->
end, [".compact", ".compact.data", ".compact.meta"]),
couch_file:delete(Server#server.root_dir, FullFilepath ++ ".compact"),
+ couch_db_plugin:on_delete(DbName, Options),
+
Async = not lists:member(sync, Options),
case couch_file:delete(Server#server.root_dir, FullFilepath, Async) of
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/311ba943/test/couch_db_plugin_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_db_plugin_tests.erl b/test/couch_db_plugin_tests.erl
index ae9f9d6..cd563b6 100644
--- a/test/couch_db_plugin_tests.erl
+++ b/test/couch_db_plugin_tests.erl
@@ -17,7 +17,8 @@
before_doc_update/2,
after_doc_read/2,
validate_docid/1,
- check_is_admin/1
+ check_is_admin/1,
+ on_delete/2
]).
-include_lib("couch/include/couch_eunit.hrl").
@@ -60,6 +61,10 @@ check_is_admin({true, _Db}) -> true;
check_is_admin({false, _Db}) -> false;
check_is_admin({fail, _Db}) -> throw(check_is_admin).
+on_delete(true, _Opts) -> true;
+on_delete(false, _Opts) -> false;
+on_delete(fail, _Opts) -> throw(on_delete).
+
callback_test_() ->
{
"callback tests",
@@ -84,7 +89,11 @@ callback_test_() ->
fun check_is_admin_match/0,
fun check_is_admin_no_match/0,
- fun check_is_admin_throw/0
+ fun check_is_admin_throw/0,
+
+ fun on_delete_match/0,
+ fun on_delete_no_match/0,
+ fun on_delete_throw/0
]
}
}.
@@ -167,3 +176,18 @@ check_is_admin_throw() ->
?assertThrow(
check_is_admin,
couch_db_plugin:check_is_admin({fail, [db]})).
+
+on_delete_match() ->
+ ?_assertMatch(
+ true,
+ couch_db_plugin:on_delete(true, [])).
+
+on_delete_no_match() ->
+ ?_assertMatch(
+ false,
+ couch_db_plugin:on_delete(false, [])).
+
+on_delete_throw() ->
+ ?assertThrow(
+ on_delete,
+ couch_db_plugin:on_delete(fail, [])).