summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Lebedeff <alebedev@mirantis.com>2017-05-18 19:48:30 +0300
committerAlexey Lebedeff <alebedev@mirantis.com>2017-05-22 16:40:48 +0300
commitab66157805aecdc07675418229511154ecb423e7 (patch)
tree49ca6a3b0c7c9e868cbbb040e05a8767e5f58e12
parentced8290812301cb2101b429d0cf1a6d7916daba2 (diff)
downloadrabbitmq-server-git-ab66157805aecdc07675418229511154ecb423e7.tar.gz
Don't expand plugins that are already unpacked
This prevents creating unnecessary files when running in embedded mode, and in development mode it keeps code path clean and compatible with different interactive tools. Also some new error conditions are properly handled and logged: - Failure to unpack an .ez-file - Missing .app file in plugin directory
-rw-r--r--src/rabbit_plugins.erl41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl
index a5d7de56bb..0a82203678 100644
--- a/src/rabbit_plugins.erl
+++ b/src/rabbit_plugins.erl
@@ -103,7 +103,7 @@ setup() ->
%% @doc Lists the plugins which are currently running.
active() ->
- InstalledPlugins = plugin_names(list(plugins_expand_dir())),
+ InstalledPlugins = plugin_names(list(plugins_dist_dir())),
[App || {App, _, _} <- rabbit_misc:which_applications(),
lists:member(App, InstalledPlugins)].
@@ -200,9 +200,6 @@ prepare_plugins(Enabled) ->
end,
[prepare_plugin(Plugin, ExpandDir) || Plugin <- WantedPlugins],
-
- [prepare_dir_plugin(PluginAppDescPath) ||
- PluginAppDescPath <- filelib:wildcard(ExpandDir ++ "/*/ebin/*.app")],
Wanted.
clean_plugins(Plugins) ->
@@ -250,11 +247,37 @@ delete_recursively(Fn) ->
{error, {Path, E}} -> {error, {cannot_delete, Path, E}}
end.
-prepare_plugin(#plugin{type = ez, location = Location}, ExpandDir) ->
- zip:unzip(Location, [{cwd, ExpandDir}]);
-prepare_plugin(#plugin{type = dir, name = Name, location = Location},
- ExpandDir) ->
- rabbit_file:recursive_copy(Location, filename:join([ExpandDir, Name])).
+find_unzipped_app_file(ExpandDir, Files) ->
+ StripComponents = length(filename:split(ExpandDir)),
+ [ X || X <- Files,
+ [_AppName, "ebin", MaybeAppFile] <-
+ [lists:nthtail(StripComponents, filename:split(X))],
+ lists:suffix(".app", MaybeAppFile)
+ ].
+
+prepare_plugin(#plugin{type = ez, name = Name, location = Location}, ExpandDir) ->
+ case zip:unzip(Location, [{cwd, ExpandDir}]) of
+ {ok, Files} ->
+ case find_unzipped_app_file(ExpandDir, Files) of
+ [PluginAppDescPath|_] ->
+ prepare_dir_plugin(PluginAppDescPath);
+ _ ->
+ rabbit_log:error("Plugin archive '~s' doesn't contain .app file~n", [Location]),
+ throw({no_plugin_app_file_in_archive, Name, Location})
+ end;
+ {error, Reason} ->
+ rabbit_log:error("Plugin archive '~s' unpacking failed: ~p~n", [Location, Reason]),
+ throw({plugin_unpack_failed, Name, Location, Reason})
+ end;
+prepare_plugin(#plugin{type = dir, location = Location, name = Name},
+ _ExpandDir) ->
+ case filelib:wildcard(Location ++ "/ebin/*.app") of
+ [PluginAppDescPath|_] ->
+ prepare_dir_plugin(PluginAppDescPath);
+ _ ->
+ rabbit_log:error("Plugin directory '~s' doesn't contain an .app file~n", [Location]),
+ throw({no_plugin_app_file_in_directory, Name, Location})
+ end.
plugin_info({ez, EZ}) ->
case read_app_file(EZ) of