fix(dialyzer): guard test can never succeed
This commit is contained in:
parent
1e14a6086e
commit
56c6cf560a
|
@ -53,8 +53,8 @@ save_files_return_opts(Options, SubDir, ResId) ->
|
||||||
%% Returns ssl options for Erlang's ssl application.
|
%% Returns ssl options for Erlang's ssl application.
|
||||||
-spec save_files_return_opts(opts_input(), file:name_all()) -> opts().
|
-spec save_files_return_opts(opts_input(), file:name_all()) -> opts().
|
||||||
save_files_return_opts(Options, Dir) ->
|
save_files_return_opts(Options, Dir) ->
|
||||||
GetD = fun(Key, Default) -> maps:get(key_to_atom(Key), Options, Default) end,
|
GetD = fun(Key, Default) -> fuzzy_map_get(Key, Options, Default) end,
|
||||||
Get = fun(Key) -> GetD(key_to_atom(Key), undefined) end,
|
Get = fun(Key) -> GetD(Key, undefined) end,
|
||||||
KeyFile = Get(keyfile),
|
KeyFile = Get(keyfile),
|
||||||
CertFile = Get(certfile),
|
CertFile = Get(certfile),
|
||||||
CAFile = GetD(cacertfile, Get(cafile)),
|
CAFile = GetD(cacertfile, Get(cafile)),
|
||||||
|
@ -77,7 +77,7 @@ save_files_return_opts(Options, Dir) ->
|
||||||
-spec save_file(file_input(), atom() | string() | binary()) -> string().
|
-spec save_file(file_input(), atom() | string() | binary()) -> string().
|
||||||
save_file(Param, SubDir) ->
|
save_file(Param, SubDir) ->
|
||||||
Dir = filename:join([emqx:get_env(data_dir), SubDir]),
|
Dir = filename:join([emqx:get_env(data_dir), SubDir]),
|
||||||
do_save_file( Param, Dir).
|
do_save_file(Param, Dir).
|
||||||
|
|
||||||
filter([]) -> [];
|
filter([]) -> [];
|
||||||
filter([{_, ""} | T]) -> filter(T);
|
filter([{_, ""} | T]) -> filter(T);
|
||||||
|
@ -86,10 +86,10 @@ filter([H | T]) -> [H | filter(T)].
|
||||||
do_save_file(#{filename := FileName, file := Content}, Dir)
|
do_save_file(#{filename := FileName, file := Content}, Dir)
|
||||||
when FileName =/= undefined andalso Content =/= undefined ->
|
when FileName =/= undefined andalso Content =/= undefined ->
|
||||||
do_save_file(ensure_str(FileName), iolist_to_binary(Content), Dir);
|
do_save_file(ensure_str(FileName), iolist_to_binary(Content), Dir);
|
||||||
do_save_file(FilePath, _) when is_binary(FilePath) ->
|
|
||||||
ensure_str(FilePath);
|
|
||||||
do_save_file(FilePath, _) when is_list(FilePath) ->
|
do_save_file(FilePath, _) when is_list(FilePath) ->
|
||||||
FilePath;
|
FilePath;
|
||||||
|
do_save_file(FilePath, _) when is_binary(FilePath) ->
|
||||||
|
ensure_str(FilePath);
|
||||||
do_save_file(_, _) -> "".
|
do_save_file(_, _) -> "".
|
||||||
|
|
||||||
do_save_file("", _, _Dir) -> ""; %% ignore
|
do_save_file("", _, _Dir) -> ""; %% ignore
|
||||||
|
@ -108,7 +108,11 @@ do_save_file(FileName, Content, Dir) ->
|
||||||
ensure_str(L) when is_list(L) -> L;
|
ensure_str(L) when is_list(L) -> L;
|
||||||
ensure_str(B) when is_binary(B) -> unicode:characters_to_list(B, utf8).
|
ensure_str(B) when is_binary(B) -> unicode:characters_to_list(B, utf8).
|
||||||
|
|
||||||
key_to_atom(B) when is_binary(B) ->
|
-spec fuzzy_map_get(atom() | binary(), map(), any()) -> any().
|
||||||
binary_to_atom(B, utf8);
|
fuzzy_map_get(Key, Options, Default) ->
|
||||||
key_to_atom(A) when is_atom(A) ->
|
case maps:find(Key, Options) of
|
||||||
A.
|
{ok, Val} -> Val;
|
||||||
|
error when is_atom(Key) ->
|
||||||
|
fuzzy_map_get(atom_to_binary(Key, utf8), Options, Default);
|
||||||
|
error -> Default
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue