chore: format emqx apps

This commit is contained in:
JianBo He 2022-04-21 21:34:21 +08:00
parent d6a9072bb0
commit ae1b435ace
4 changed files with 22 additions and 14 deletions

View File

@ -322,7 +322,8 @@ delete_old_file(_New, Old) ->
case is_generated_file(Old) andalso filelib:is_regular(Old) andalso file:delete(Old) of case is_generated_file(Old) andalso filelib:is_regular(Old) andalso file:delete(Old) of
ok -> ok ->
ok; ok;
false -> %% the file is not generated by us, or it is already deleted %% the file is not generated by us, or it is already deleted
false ->
ok; ok;
{error, Reason} -> {error, Reason} ->
?SLOG(error, #{msg => "failed_to_delete_ssl_file", file_path => Old, reason => Reason}) ?SLOG(error, #{msg => "failed_to_delete_ssl_file", file_path => Old, reason => Reason})
@ -412,16 +413,21 @@ pem_dir(Dir) ->
filename:join([emqx:mutable_certs_dir(), Dir]). filename:join([emqx:mutable_certs_dir(), Dir]).
is_hex_str(HexStr) -> is_hex_str(HexStr) ->
try is_hex_str2(ensure_str(HexStr)) try
catch throw: not_hex -> false is_hex_str2(ensure_str(HexStr))
catch
throw:not_hex -> false
end. end.
is_hex_str2(HexStr) -> is_hex_str2(HexStr) ->
_ = [case S of _ = [
case S of
S when S >= $0, S =< $9 -> S; S when S >= $0, S =< $9 -> S;
S when S >= $a, S =< $f -> S; S when S >= $a, S =< $f -> S;
_ -> throw(not_hex) _ -> throw(not_hex)
end || S <- HexStr], end
|| S <- HexStr
],
true. true.
hex_str(Bin) -> hex_str(Bin) ->
@ -457,8 +463,7 @@ do_drop_invalid_certs([Key | Keys], SSL) ->
PemOrPath -> PemOrPath ->
case is_pem(PemOrPath) orelse is_valid_pem_file(PemOrPath) of case is_pem(PemOrPath) orelse is_valid_pem_file(PemOrPath) of
true -> do_drop_invalid_certs(Keys, SSL); true -> do_drop_invalid_certs(Keys, SSL);
{error, _} -> {error, _} -> do_drop_invalid_certs(Keys, maps:without([Key], SSL))
do_drop_invalid_certs(Keys, maps:without([Key], SSL))
end end
end. end.

View File

@ -488,7 +488,8 @@ is_tcp_server_available(Host, Port, Timeout) ->
start_ekka() -> start_ekka() ->
try mnesia_hook:module_info() of try mnesia_hook:module_info() of
_ -> ekka:start() _ -> ekka:start()
catch _:_ -> catch
_:_ ->
%% Falling back to using Mnesia DB backend. %% Falling back to using Mnesia DB backend.
application:set_env(mria, db_backend, mnesia), application:set_env(mria, db_backend, mnesia),
ekka:start() ekka:start()

View File

@ -223,7 +223,9 @@ t_callback_crash(_Config) ->
Opts = #{rawconf_with_defaults => true}, Opts = #{rawconf_with_defaults => true},
ok = emqx_config_handler:add_handler(CrashPath, ?MODULE), ok = emqx_config_handler:add_handler(CrashPath, ?MODULE),
Old = emqx:get_raw_config(CrashPath), Old = emqx:get_raw_config(CrashPath),
?assertMatch({error, {config_update_crashed, _}}, emqx:update_config(CrashPath, <<"89%">>, Opts)), ?assertMatch(
{error, {config_update_crashed, _}}, emqx:update_config(CrashPath, <<"89%">>, Opts)
),
New = emqx:get_raw_config(CrashPath), New = emqx:get_raw_config(CrashPath),
?assertEqual(Old, New), ?assertEqual(Old, New),
ok = emqx_config_handler:remove_handler(CrashPath), ok = emqx_config_handler:remove_handler(CrashPath),