Skip to content

Commit 2044cb1

Browse files
Gerhard Lazugerhard
authored andcommitted
Use the code path to find loaded plugins
We were using the expand_dir before, which no longer exists Signed-off-by: Jean-Sébastien Pedron <[email protected]> [#118562759]
1 parent 76a8c66 commit 2044cb1

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

src/rabbit_plugins.erl

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,56 @@ extract_schema(#plugin{type = dir, location = Location}, SchemaDir) ->
135135

136136
%% @doc Lists the plugins which are currently running.
137137
active() ->
138-
{ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir),
139-
InstalledPlugins = plugin_names(list(ExpandDir)),
138+
LoadedPluginNames = maybe_keep_required_deps(false, loaded_plugin_names()),
140139
[App || {App, _, _} <- rabbit_misc:which_applications(),
141-
lists:member(App, InstalledPlugins)].
140+
lists:member(App, LoadedPluginNames)].
141+
142+
loaded_plugin_names() ->
143+
{ok, PluginsDir} = application:get_env(rabbit, plugins_dir),
144+
PluginsDirComponents = filename:split(PluginsDir),
145+
loaded_plugin_names(code:get_path(), PluginsDirComponents, []).
146+
147+
loaded_plugin_names([Path | OtherPaths], PluginsDirComponents, PluginNames) ->
148+
case lists:sublist(filename:split(Path), length(PluginsDirComponents)) of
149+
PluginsDirComponents ->
150+
case build_plugin_name_from_code_path(Path) of
151+
undefined ->
152+
loaded_plugin_names(
153+
OtherPaths, PluginsDirComponents, PluginNames);
154+
PluginName ->
155+
loaded_plugin_names(
156+
OtherPaths, PluginsDirComponents,
157+
[list_to_atom(PluginName) | PluginNames])
158+
end;
159+
_ ->
160+
loaded_plugin_names(OtherPaths, PluginsDirComponents, PluginNames)
161+
end;
162+
loaded_plugin_names([], _, PluginNames) ->
163+
PluginNames.
164+
165+
build_plugin_name_from_code_path(Path) ->
166+
AppPath = case filelib:is_dir(Path) of
167+
true ->
168+
case filelib:wildcard(filename:join(Path, "*.app")) of
169+
[AP | _] -> AP;
170+
[] -> undefined
171+
end;
172+
false ->
173+
EZ = filename:dirname(filename:dirname(Path)),
174+
case filelib:is_regular(EZ) of
175+
true ->
176+
case find_app_path_in_ez(EZ) of
177+
{ok, AP} -> AP;
178+
_ -> undefined
179+
end;
180+
_ ->
181+
undefined
182+
end
183+
end,
184+
case AppPath of
185+
undefined -> undefined;
186+
_ -> filename:basename(AppPath, ".app")
187+
end.
142188

143189
%% @doc Get the list of plugins which are ready to be enabled.
144190
list(PluginsPath) ->

0 commit comments

Comments
 (0)