mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
parent
68fb12153e
commit
9bd099013f
@ -28,7 +28,7 @@
|
||||
|
||||
-export([start/0, load_file/1, reload_file/0, read_file/1,
|
||||
get_option/1, get_option/2, add_option/2, has_option/1,
|
||||
get_vh_by_auth_method/1, is_file_readable/1,
|
||||
get_vh_by_auth_method/1,
|
||||
get_version/0, get_myhosts/0, get_mylang/0, get_lang/1,
|
||||
get_ejabberd_config_path/0, is_using_elixir_config/0,
|
||||
prepare_opt_val/4, transform_options/1, collect_options/1,
|
||||
@ -46,11 +46,12 @@
|
||||
get_global_option/2, get_local_option/2,
|
||||
get_global_option/3, get_local_option/3,
|
||||
get_option/3]).
|
||||
-export([is_file_readable/1]).
|
||||
|
||||
-deprecated([{add_global_option, 2}, {add_local_option, 2},
|
||||
{get_global_option, 2}, {get_local_option, 2},
|
||||
{get_global_option, 3}, {get_local_option, 3},
|
||||
{get_option, 3}]).
|
||||
{get_option, 3}, {is_file_readable, 1}]).
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("logger.hrl").
|
||||
|
20
src/misc.erl
20
src/misc.erl
@ -204,22 +204,12 @@ join_atoms(Atoms, Sep) ->
|
||||
%% in configuration validators only.
|
||||
-spec try_read_file(file:filename_all()) -> binary().
|
||||
try_read_file(Path) ->
|
||||
Res = case file:read_file_info(Path) of
|
||||
{ok, #file_info{type = Type, access = Access}} ->
|
||||
case {Type, Access} of
|
||||
{regular, read} -> ok;
|
||||
{regular, read_write} -> ok;
|
||||
{regular, _} -> {error, file:format_error(eaccess)};
|
||||
_ -> {error, "not a regular file"}
|
||||
end;
|
||||
{error, Why} ->
|
||||
{error, file:format_error(Why)}
|
||||
end,
|
||||
case Res of
|
||||
ok ->
|
||||
case file:open(Path, [read]) of
|
||||
{ok, Fd} ->
|
||||
file:close(Fd),
|
||||
iolist_to_binary(Path);
|
||||
{error, Reason} ->
|
||||
?ERROR_MSG("Failed to read ~s: ~s", [Path, Reason]),
|
||||
{error, Why} ->
|
||||
?ERROR_MSG("Failed to read ~s: ~s", [Path, file:format_error(Why)]),
|
||||
erlang:error(badarg)
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user