add `uninstall()`, removed unneeded aplication:load() cruft
diff --git a/src/couch_plugins.erl b/src/couch_plugins.erl
index 8b4a22a..3463d3d 100644
--- a/src/couch_plugins.erl
+++ b/src/couch_plugins.erl
@@ -43,9 +43,6 @@
ok = register_plugin(Name, Version),
log("registered plugin"),
- ok = load_plugin(Name),
- log("loaded plugin"),
-
load_config(Name, Version),
log("loaded config"),
@@ -55,10 +52,6 @@
% plugin, you get an `ok`.
-spec uninstall(plugin()) -> ok | {error, string()}.
uninstall({Name, _BaseUrl, Version, _Checksums}) ->
- % unload app
- ok = unload_plugin(Name),
- log("plugin unloaded"),
-
% unload config
ok = unload_config(Name, Version),
log("config unloaded"),
@@ -125,7 +118,7 @@
ok = couch_config:set(Section, Key, Value).
-spec delete_config({{string(), string()}, _Value}) -> ok.
-delete_config({Section, Key}) ->
+delete_config({{Section, Key}, _Value}) ->
ok = couch_config:delete(Section, Key).
-spec file_names(string(), string()) -> string().
@@ -166,23 +159,6 @@
%% * * *
-%% Load Plugin
-%% This uses `appliction:load(<plugnname>)` to load the plugin
-%% and `appliction:unload(<plugnname>)` to unload the plugin.
-
--spec load_plugin(string()) -> ok | {error, atom()}.
-load_plugin(NameList) ->
- Name = list_to_atom(NameList),
- application:load(Name).
-
--spec unload_plugin(string()) -> ok | {error, atom()}.
-unload_plugin(NameList) ->
- Name = list_to_atom(NameList),
- application:unload(Name).
-
-%% * * *
-
-
-spec untargz(string()) -> {ok, string()} | {error, string()}.
untargz(Filename) ->
% read .gz file
@@ -197,7 +173,8 @@
-spec delete_files(string(), string()) -> ok | {error, atom()}.
delete_files(Name, Version) ->
PluginPath = plugin_dir() ++ "/" ++ get_file_slug(Name, Version),
- file:del_dir(PluginPath).
+ mochitemp:rmtempdir(PluginPath).
+
% downloads a pluygin .tar.gz into a local plugins directory
-spec download(string()) -> ok | {error, string()}.
diff --git a/src/couch_plugins_httpd.erl b/src/couch_plugins_httpd.erl
index 7a450f4..7a99cd1 100644
--- a/src/couch_plugins_httpd.erl
+++ b/src/couch_plugins_httpd.erl
@@ -20,16 +20,18 @@
couch_httpd:validate_ctype(Req, "application/json"),
{PluginSpec} = couch_httpd:json_body_obj(Req),
- ?LOG_DEBUG("Plugin Spec: ~p", [PluginSpec]),
Url = binary_to_list(couch_util:get_value(<<"url">>, PluginSpec)),
Name = binary_to_list(couch_util:get_value(<<"name">>, PluginSpec)),
Version = binary_to_list(couch_util:get_value(<<"version">>, PluginSpec)),
+ Delete = couch_util:get_value(<<"delete">>, PluginSpec),
{Checksums0} = couch_util:get_value(<<"checksums">>, PluginSpec),
Checksums = lists:map(fun({K, V}) ->
{binary_to_list(K), binary_to_list(V)}
end, Checksums0),
-
- case couch_plugins:install({Name, Url, Version, Checksums}) of
+ Plugin = {Name, Url, Version, Checksums},
+ ?LOG_DEBUG("~p", [Plugin]),
+ ?LOG_DEBUG("~p", [Delete]),
+ case do_install(Delete, Plugin) of
ok ->
couch_httpd:send_json(Req, 202, {[{ok, true}]});
Error ->
@@ -38,3 +40,8 @@
end;
handle_req(Req) ->
couch_httpd:send_method_not_allowed(Req, "POST").
+
+do_install(false, Plugin)->
+ couch_plugins:install(Plugin);
+do_install(true, Plugin)->
+ couch_plugins:uninstall(Plugin).