Skip to content

Commit da982ef

Browse files
Merge branch 'binarin-dont-expand-dir-plugins-master'
2 parents 915f1e9 + fb17eed commit da982ef

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

src/rabbit_plugins.erl

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ extract_schema(#plugin{type = dir, location = Location}, SchemaDir) ->
157157

158158
%% @doc Lists the plugins which are currently running.
159159
active() ->
160-
InstalledPlugins = plugin_names(list(plugins_expand_dir())),
160+
InstalledPlugins = plugin_names(list(plugins_dist_dir())),
161161
[App || {App, _, _} <- rabbit_misc:which_applications(),
162162
lists:member(App, InstalledPlugins)].
163163

@@ -213,8 +213,7 @@ strictly_plugins(Plugins, AllPlugins) ->
213213
end, Plugins).
214214

215215
strictly_plugins(Plugins) ->
216-
ExpandDir = plugins_expand_dir(),
217-
AllPlugins = list(ExpandDir),
216+
AllPlugins = list(plugins_dist_dir()),
218217
lists:filter(
219218
fun(Name) ->
220219
is_strictly_plugin(lists:keyfind(Name, #plugin.name, AllPlugins))
@@ -280,10 +279,8 @@ prepare_plugins(Enabled) ->
280279
{error, E2} -> throw({error, {cannot_create_plugins_expand_dir,
281280
[ExpandDir, E2]}})
282281
end,
283-
[prepare_plugin(Plugin, ExpandDir) || Plugin <- ValidPlugins],
284282

285-
[prepare_dir_plugin(PluginAppDescPath) ||
286-
PluginAppDescPath <- filelib:wildcard(ExpandDir ++ "/*/ebin/*.app")],
283+
[prepare_plugin(Plugin, ExpandDir) || Plugin <- ValidPlugins],
287284
Wanted.
288285

289286
maybe_warn_about_invalid_plugins([]) ->
@@ -460,11 +457,37 @@ delete_recursively(Fn) ->
460457
{error, {Path, E}} -> {error, {cannot_delete, Path, E}}
461458
end.
462459

463-
prepare_plugin(#plugin{type = ez, location = Location}, ExpandDir) ->
464-
zip:unzip(Location, [{cwd, ExpandDir}]);
465-
prepare_plugin(#plugin{type = dir, name = Name, location = Location},
466-
ExpandDir) ->
467-
rabbit_file:recursive_copy(Location, filename:join([ExpandDir, Name])).
460+
find_unzipped_app_file(ExpandDir, Files) ->
461+
StripComponents = length(filename:split(ExpandDir)),
462+
[ X || X <- Files,
463+
[_AppName, "ebin", MaybeAppFile] <-
464+
[lists:nthtail(StripComponents, filename:split(X))],
465+
lists:suffix(".app", MaybeAppFile)
466+
].
467+
468+
prepare_plugin(#plugin{type = ez, name = Name, location = Location}, ExpandDir) ->
469+
case zip:unzip(Location, [{cwd, ExpandDir}]) of
470+
{ok, Files} ->
471+
case find_unzipped_app_file(ExpandDir, Files) of
472+
[PluginAppDescPath|_] ->
473+
prepare_dir_plugin(PluginAppDescPath);
474+
_ ->
475+
rabbit_log:error("Plugin archive '~s' doesn't contain an .app file~n", [Location]),
476+
throw({app_file_missing, Name, Location})
477+
end;
478+
{error, Reason} ->
479+
rabbit_log:error("Could not unzip plugin archive '~s': ~p~n", [Location, Reason]),
480+
throw({failed_to_unzip_plugin, Name, Location, Reason})
481+
end;
482+
prepare_plugin(#plugin{type = dir, location = Location, name = Name},
483+
_ExpandDir) ->
484+
case filelib:wildcard(Location ++ "/ebin/*.app") of
485+
[PluginAppDescPath|_] ->
486+
prepare_dir_plugin(PluginAppDescPath);
487+
_ ->
488+
rabbit_log:error("Plugin directory '~s' doesn't contain an .app file~n", [Location]),
489+
throw({app_file_missing, Name, Location})
490+
end.
468491

469492
plugin_info({ez, EZ}) ->
470493
case read_app_file(EZ) of

0 commit comments

Comments
 (0)