Skip to content

Commit 9084194

Browse files
Merge pull request #1226 from binarin/dont-expand-dir-plugins-stable
Don't expand plugins that are already unpacked
2 parents 904e527 + 7c8ccae commit 9084194

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

src/rabbit_plugins.erl

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ setup() ->
103103

104104
%% @doc Lists the plugins which are currently running.
105105
active() ->
106-
InstalledPlugins = plugin_names(list(plugins_expand_dir())),
106+
InstalledPlugins = plugin_names(list(plugins_dist_dir())),
107107
[App || {App, _, _} <- rabbit_misc:which_applications(),
108108
lists:member(App, InstalledPlugins)].
109109

@@ -200,9 +200,6 @@ prepare_plugins(Enabled) ->
200200
end,
201201

202202
[prepare_plugin(Plugin, ExpandDir) || Plugin <- WantedPlugins],
203-
204-
[prepare_dir_plugin(PluginAppDescPath) ||
205-
PluginAppDescPath <- filelib:wildcard(ExpandDir ++ "/*/ebin/*.app")],
206203
Wanted.
207204

208205
clean_plugins(Plugins) ->
@@ -250,11 +247,37 @@ delete_recursively(Fn) ->
250247
{error, {Path, E}} -> {error, {cannot_delete, Path, E}}
251248
end.
252249

253-
prepare_plugin(#plugin{type = ez, location = Location}, ExpandDir) ->
254-
zip:unzip(Location, [{cwd, ExpandDir}]);
255-
prepare_plugin(#plugin{type = dir, name = Name, location = Location},
256-
ExpandDir) ->
257-
rabbit_file:recursive_copy(Location, filename:join([ExpandDir, Name])).
250+
find_unzipped_app_file(ExpandDir, Files) ->
251+
StripComponents = length(filename:split(ExpandDir)),
252+
[ X || X <- Files,
253+
[_AppName, "ebin", MaybeAppFile] <-
254+
[lists:nthtail(StripComponents, filename:split(X))],
255+
lists:suffix(".app", MaybeAppFile)
256+
].
257+
258+
prepare_plugin(#plugin{type = ez, name = Name, location = Location}, ExpandDir) ->
259+
case zip:unzip(Location, [{cwd, ExpandDir}]) of
260+
{ok, Files} ->
261+
case find_unzipped_app_file(ExpandDir, Files) of
262+
[PluginAppDescPath|_] ->
263+
prepare_dir_plugin(PluginAppDescPath);
264+
_ ->
265+
rabbit_log:error("Plugin archive '~s' doesn't contain an .app file~n", [Location]),
266+
throw({app_file_missing, Name, Location})
267+
end;
268+
{error, Reason} ->
269+
rabbit_log:error("Could not unzip plugin archive '~s': ~p~n", [Location, Reason]),
270+
throw({failed_to_unzip_plugin, Name, Location, Reason})
271+
end;
272+
prepare_plugin(#plugin{type = dir, location = Location, name = Name},
273+
_ExpandDir) ->
274+
case filelib:wildcard(Location ++ "/ebin/*.app") of
275+
[PluginAppDescPath|_] ->
276+
prepare_dir_plugin(PluginAppDescPath);
277+
_ ->
278+
rabbit_log:error("Plugin directory '~s' doesn't contain an .app file~n", [Location]),
279+
throw({app_file_missing, Name, Location})
280+
end.
258281

259282
plugin_info({ez, EZ}) ->
260283
case read_app_file(EZ) of

0 commit comments

Comments
 (0)