From c5c7e7fc4db97022986d1595b73781571a3d59f2 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 25 Jan 2023 13:25:56 +0100 Subject: [PATCH] ext_mod: Improve support for loading *.so files from ext_mod dependencies Copying files from deps/*/priv/*.so to the ejabberd priv/ is not possible when running ejabberd as OTP release or in a container. Instead, let's copy the deps/*/priv/*.so maintaining the file structure, and then using code:add_pathz for those dirs. This partially reverts 5c1b72853f8cfcd25d1ed6231a9f1c78ea19b95e --- src/ext_mod.erl | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ext_mod.erl b/src/ext_mod.erl index e3176d29e..32f1f6fc8 100644 --- a/src/ext_mod.erl +++ b/src/ext_mod.erl @@ -66,7 +66,7 @@ init([]) -> {ok, #state{}}. add_paths() -> - [code:add_patha(module_ebin_dir(Module)) + [code:add_pathsz([module_ebin_dir(Module)|module_deps_dirs(Module)]) || {Module, _} <- installed()]. handle_call(Request, From, State) -> @@ -229,7 +229,7 @@ install(Package) when is_binary(Package) -> Module = misc:binary_to_atom(Package), case compile_and_install(Module, Attrs) of ok -> - code:add_patha(module_ebin_dir(Module)), + code:add_pathsz([module_ebin_dir(Module)|module_deps_dirs(Module)]), ejabberd_config:reload(), copy_commit_json(Package, Attrs), case erlang:function_exported(Module, post_install, 0) of @@ -256,7 +256,7 @@ uninstall(Package) when is_binary(Package) -> || Host <- ejabberd_option:hosts()], code:purge(Module), code:delete(Module), - code:del_path(module_ebin_dir(Module)), + [code:del_path(PathDelete) || PathDelete <- [module_ebin_dir(Module)|module_deps_dirs(Module)]], delete_path(module_lib_dir(Module)), ejabberd_config:reload(); false -> @@ -654,11 +654,12 @@ install(Module, Spec, SrcDir, LibDir) -> Files1 = [{File, copy(File, filename:join(LibDir, File))} || File <- filelib:wildcard("{ebin,priv,conf,include}/**")], Files2 = [{File, copy(File, filename:join(LibDir, filename:join(lists:nthtail(2,filename:split(File)))))} - || File <- filelib:wildcard("deps/*/{ebin,priv}/**")], + || File <- filelib:wildcard("deps/*/ebin/**")], + Files3 = [{File, copy(File, filename:join(LibDir, File))} + || File <- filelib:wildcard("deps/*/priv/**")], Errors = lists:dropwhile(fun({_, ok}) -> true; (_) -> false - end, Files1++Files2), - copy_priv_files(LibDir), + end, Files1++Files2++Files3), inform_module_configuration(Module, LibDir, Files1), Result = case Errors of [{F, {error, E}}|_] -> @@ -671,12 +672,6 @@ install(Module, Spec, SrcDir, LibDir) -> file:set_cwd(CurDir), Result. -copy_priv_files(LibDir) -> - file:set_cwd(LibDir), - EjabberdLibDir = code:lib_dir(ejabberd), - [{File, copy(File, filename:join(EjabberdLibDir, File))} - || File <- filelib:wildcard("{priv}/**")]. - inform_module_configuration(Module, LibDir, Files1) -> Res = lists:filter(fun({[$c, $o, $n, $f |_], ok}) -> true; (_) -> false @@ -736,6 +731,14 @@ rebar_dep({App, _, {git, Url, Ref}}) -> "; (cd "++filename:basename(App)++ "; git checkout -q "++Ref++")"}. +module_deps_dirs(Module) -> + SrcDir = module_src_dir(Module), + LibDir = module_lib_dir(Module), + DepsDir = filename:join(LibDir, "deps"), + Deps = rebar_deps(filename:join(SrcDir, "rebar.config")) + ++ rebar_deps(filename:join(SrcDir, "rebar.config.script")), + [filename:join(DepsDir, App) || {App, _Cmd} <- Deps]. + %% -- YAML spec parser consult(File) ->