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 -*-
{application, emqx_plugins, [
{description, "EMQX Plugin Management"},
{vsn, "0.2.0"},
{vsn, "0.2.1"},
{modules, []},
{mod, {emqx_plugins_app, []}},
{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) ->
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
@ -1372,12 +1385,14 @@ plugin_dir(NameVsn) ->
-spec plugin_priv_dir(name_vsn()) -> string().
plugin_priv_dir(NameVsn) ->
case read_plugin_info(NameVsn, #{fill_readme => false}) of
{ok, #{<<"name">> := Name, <<"metadata_vsn">> := Vsn}} ->
AppDir = make_name_vsn_string(Name, Vsn),
wrap_to_list(filename:join([plugin_dir(NameVsn), AppDir, "priv"]));
_ ->
wrap_to_list(filename:join([install_dir(), NameVsn, "priv"]))
maybe
{ok, #{<<"name">> := Name, <<"rel_apps">> := Apps}} ?=
read_plugin_info(NameVsn, #{fill_readme => false}),
{ok, AppDir} ?= app_dir(Name, Apps),
wrap_to_list(filename:join([plugin_dir(NameVsn), AppDir, "priv"]))
else
%% Otherwise assume the priv directory is under the plugin root directory
_ -> wrap_to_list(filename:join([install_dir(), NameVsn, "priv"]))
end.
-spec plugin_config_dir(name_vsn()) -> string() | {error, Reason :: string()}.