From: Evgeniy Khramtsov Date: Wed, 7 Mar 2018 14:46:16 +0000 (+0300) Subject: Strip duplicates from module's options X-Git-Tag: 18.03~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3eeb8624baa639e049d113e111a6a4358d6799c;p=ejabberd Strip duplicates from module's options --- diff --git a/src/gen_mod.erl b/src/gen_mod.erl index a477ec295..836e9dba8 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -555,7 +555,8 @@ validate_opts(Host, Module, Opts0) -> undef -> Opts; Validators -> - validate_opts(Host, Module, Opts, Required, Validators) + Opts1 = validate_opts(Host, Module, Opts, Required, Validators), + remove_duplicated_opts(Opts1) end} catch _:{missing_required_option, Opt} -> ErrTxt = io_lib:format("Module '~s' is missing required option '~s'", @@ -680,6 +681,16 @@ merge_opts(Opts, DefaultOpts) -> end end, Result, Opts). +remove_duplicated_opts([{Opt, Val}, {Opt, _Default}|Opts]) -> + [{Opt, Val}|remove_duplicated_opts(Opts)]; +remove_duplicated_opts([{Opt, [{SubOpt, _}|_] = SubOpts}|Opts]) + when is_atom(SubOpt) -> + [{Opt, remove_duplicated_opts(SubOpts)}|remove_duplicated_opts(Opts)]; +remove_duplicated_opts([OptVal|Opts]) -> + [OptVal|remove_duplicated_opts(Opts)]; +remove_duplicated_opts([]) -> + []. + -spec get_submodules(binary(), module(), opts()) -> [module()]. get_submodules(Host, Module, Opts) -> try Module:mod_options(Host) of