Merge pull request #13145 from JimMoen/fix-plugin-app-priv-path

This commit is contained in:
JimMoen 2024-06-04 09:17:48 +08:00 committed by GitHub
commit 93d5e77698
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 7 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_plugins, [ {application, emqx_plugins, [
{description, "EMQX Plugin Management"}, {description, "EMQX Plugin Management"},
{vsn, "0.2.0"}, {vsn, "0.2.1"},
{modules, []}, {modules, []},
{mod, {emqx_plugins_app, []}}, {mod, {emqx_plugins_app, []}},
{applications, [kernel, stdlib, emqx, erlavro]}, {applications, [kernel, stdlib, emqx, erlavro]},

View File

@ -136,6 +136,19 @@ parse_name_vsn(NameVsn) when is_list(NameVsn) ->
make_name_vsn_string(Name, Vsn) -> make_name_vsn_string(Name, Vsn) ->
binary_to_list(iolist_to_binary([Name, "-", Vsn])). binary_to_list(iolist_to_binary([Name, "-", Vsn])).
app_dir(AppName, Apps) ->
case
lists:filter(
fun(AppNameVsn) -> nomatch =/= string:prefix(AppNameVsn, AppName) end,
Apps
)
of
[AppNameVsn] ->
{ok, AppNameVsn};
_ ->
{error, not_found}
end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Package operations %% Package operations
@ -1372,12 +1385,14 @@ plugin_dir(NameVsn) ->
-spec plugin_priv_dir(name_vsn()) -> string(). -spec plugin_priv_dir(name_vsn()) -> string().
plugin_priv_dir(NameVsn) -> plugin_priv_dir(NameVsn) ->
case read_plugin_info(NameVsn, #{fill_readme => false}) of maybe
{ok, #{<<"name">> := Name, <<"metadata_vsn">> := Vsn}} -> {ok, #{<<"name">> := Name, <<"rel_apps">> := Apps}} ?=
AppDir = make_name_vsn_string(Name, Vsn), read_plugin_info(NameVsn, #{fill_readme => false}),
wrap_to_list(filename:join([plugin_dir(NameVsn), AppDir, "priv"])); {ok, AppDir} ?= app_dir(Name, Apps),
_ -> wrap_to_list(filename:join([plugin_dir(NameVsn), AppDir, "priv"]))
wrap_to_list(filename:join([install_dir(), NameVsn, "priv"])) else
%% Otherwise assume the priv directory is under the plugin root directory
_ -> wrap_to_list(filename:join([install_dir(), NameVsn, "priv"]))
end. end.
-spec plugin_config_dir(name_vsn()) -> string() | {error, Reason :: string()}. -spec plugin_config_dir(name_vsn()) -> string() | {error, Reason :: string()}.