fix(config): write configs to emqx_override.conf failed

This commit is contained in:
Shawn 2021-07-22 16:00:23 +08:00
parent 2666c06232
commit 0a3b77f65d
1 changed files with 4 additions and 4 deletions

View File

@ -158,7 +158,7 @@ load() ->
%% the app env 'config_files' should be set before emqx get started. %% the app env 'config_files' should be set before emqx get started.
ConfFiles = application:get_env(emqx, config_files, []), ConfFiles = application:get_env(emqx, config_files, []),
RawRichConf = lists:foldl(fun(ConfFile, Acc) -> RawRichConf = lists:foldl(fun(ConfFile, Acc) ->
Raw = load_hocon_file(ConfFile), Raw = load_hocon_file(ConfFile, richmap),
emqx_map_lib:deep_merge(Acc, Raw) emqx_map_lib:deep_merge(Acc, Raw)
end, #{}, ConfFiles), end, #{}, ConfFiles),
{_MappedEnvs, RichConf} = hocon_schema:map_translate(emqx_schema, RawRichConf, #{}), {_MappedEnvs, RichConf} = hocon_schema:map_translate(emqx_schema, RawRichConf, #{}),
@ -195,7 +195,7 @@ save_to_emqx_config(Conf, RawConf) ->
-spec save_to_override_conf(config()) -> ok | {error, term()}. -spec save_to_override_conf(config()) -> ok | {error, term()}.
save_to_override_conf(Conf) -> save_to_override_conf(Conf) ->
FileName = emqx_override_conf_name(), FileName = emqx_override_conf_name(),
OldConf = load_hocon_file(FileName), OldConf = load_hocon_file(FileName, map),
MergedConf = maps:merge(OldConf, Conf), MergedConf = maps:merge(OldConf, Conf),
ok = filelib:ensure_dir(FileName), ok = filelib:ensure_dir(FileName),
case file:write_file(FileName, jsx:prettify(jsx:encode(MergedConf))) of case file:write_file(FileName, jsx:prettify(jsx:encode(MergedConf))) of
@ -205,10 +205,10 @@ save_to_override_conf(Conf) ->
{error, Reason} {error, Reason}
end. end.
load_hocon_file(FileName) -> load_hocon_file(FileName, LoadType) ->
case filelib:is_regular(FileName) of case filelib:is_regular(FileName) of
true -> true ->
{ok, Raw0} = hocon:load(FileName, #{format => richmap}), {ok, Raw0} = hocon:load(FileName, #{format => LoadType}),
Raw0; Raw0;
false -> #{} false -> #{}
end. end.