Skip to content

Commit 63ca704

Browse files
author
Alexey Lebedeff
committed
Merge 'dont-expand-dir-plugins-stable'
2 parents 915f1e9 + ab66157 commit 63ca704

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

src/rabbit_plugins.erl

Lines changed: 33 additions & 9 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

@@ -280,10 +280,8 @@ prepare_plugins(Enabled) ->
280280
{error, E2} -> throw({error, {cannot_create_plugins_expand_dir,
281281
[ExpandDir, E2]}})
282282
end,
283-
[prepare_plugin(Plugin, ExpandDir) || Plugin <- ValidPlugins],
284283

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

289287
maybe_warn_about_invalid_plugins([]) ->
@@ -460,11 +458,37 @@ delete_recursively(Fn) ->
460458
{error, {Path, E}} -> {error, {cannot_delete, Path, E}}
461459
end.
462460

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

469493
plugin_info({ez, EZ}) ->
470494
case read_app_file(EZ) of

0 commit comments

Comments
 (0)