From 4dfcb90b16d4239a43248087666a255d9cf8607b Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Thu, 3 Mar 2022 20:23:54 +0800 Subject: [PATCH] fix: get_roots broken --- apps/emqx/src/emqx_config.erl | 2 +- apps/emqx/src/emqx_config_handler.erl | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index 0c3100f11..c4cab7ce9 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -301,7 +301,7 @@ merge_envs(SchemaMod, RawConf) -> }, hocon_tconf:merge_env_overrides(SchemaMod, RawConf, all, Opts). --spec check_config(hocon_schema:shema(), raw_config()) -> {AppEnvs, CheckedConf} +-spec check_config(hocon_schema:schema(), raw_config()) -> {AppEnvs, CheckedConf} when AppEnvs :: app_envs(), CheckedConf :: config(). check_config(SchemaMod, RawConf) -> check_config(SchemaMod, RawConf, #{}). diff --git a/apps/emqx/src/emqx_config_handler.erl b/apps/emqx/src/emqx_config_handler.erl index f64b5cdf9..eb1403ec6 100644 --- a/apps/emqx/src/emqx_config_handler.erl +++ b/apps/emqx/src/emqx_config_handler.erl @@ -333,10 +333,6 @@ bin_path(ConfKeyPath) -> [bin(Key) || Key <- ConfKeyPath]. bin(A) when is_atom(A) -> atom_to_binary(A, utf8); bin(B) when is_binary(B) -> B. -list(Atom) when is_atom(Atom) -> atom_to_list(Atom); -list(Bin) when is_binary(Bin) -> binary_to_list(Bin); -list(List) when is_list(List) -> List. - atom(Bin) when is_binary(Bin) -> binary_to_atom(Bin, utf8); atom(Str) when is_list(Str) -> @@ -368,12 +364,8 @@ assert_callback_function(Mod) -> ok. schema(SchemaModule, [RootKey | _]) -> - Roots = SchemaModule:roots(), - Fields = - case lists:keyfind(list(RootKey), 1, Roots) of - false -> lists:keyfind(RootKey, 1, Roots); - Fields1 -> Fields1 - end, + Roots = hocon_schema:roots(SchemaModule), + {_, Fields} = lists:keyfind(bin(RootKey), 1, Roots), #{roots => [root], fields => #{root => [Fields]}}. load_prev_handlers() ->