mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
Make sure configuration file path always represented as binary()
Fixes #2936
This commit is contained in:
parent
bfa3125a81
commit
9dedbe30ba
@ -73,8 +73,9 @@
|
|||||||
load() ->
|
load() ->
|
||||||
load(path()).
|
load(path()).
|
||||||
|
|
||||||
-spec load(file:filename()) -> ok | error_return().
|
-spec load(file:filename_all()) -> ok | error_return().
|
||||||
load(ConfigFile) ->
|
load(Path) ->
|
||||||
|
ConfigFile = unicode:characters_to_binary(Path),
|
||||||
UnixTime = erlang:monotonic_time(second),
|
UnixTime = erlang:monotonic_time(second),
|
||||||
?INFO_MSG("Loading configuration from ~s", [ConfigFile]),
|
?INFO_MSG("Loading configuration from ~s", [ConfigFile]),
|
||||||
_ = ets:new(ejabberd_options,
|
_ = ets:new(ejabberd_options,
|
||||||
@ -353,7 +354,7 @@ format_error({error, {old_config, Path, Reason}}) ->
|
|||||||
lists:flatten(
|
lists:flatten(
|
||||||
io_lib:format(
|
io_lib:format(
|
||||||
"Failed to read configuration from '~s': ~s~s",
|
"Failed to read configuration from '~s': ~s~s",
|
||||||
[Path,
|
[unicode:characters_to_binary(Path),
|
||||||
case Reason of
|
case Reason of
|
||||||
{_, _, _} -> "at line ";
|
{_, _, _} -> "at line ";
|
||||||
_ -> ""
|
_ -> ""
|
||||||
@ -362,7 +363,8 @@ format_error({error, {write_file, Path, Reason}}) ->
|
|||||||
lists:flatten(
|
lists:flatten(
|
||||||
io_lib:format(
|
io_lib:format(
|
||||||
"Failed to write to '~s': ~s",
|
"Failed to write to '~s': ~s",
|
||||||
[Path, file:format_error(Reason)]));
|
[unicode:characters_to_binary(Path),
|
||||||
|
file:format_error(Reason)]));
|
||||||
format_error({error, {exception, Class, Reason, St}}) ->
|
format_error({error, {exception, Class, Reason, St}}) ->
|
||||||
lists:flatten(
|
lists:flatten(
|
||||||
io_lib:format(
|
io_lib:format(
|
||||||
@ -376,19 +378,20 @@ format_error({error, {exception, Class, Reason, St}}) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
-spec path() -> string().
|
-spec path() -> binary().
|
||||||
path() ->
|
path() ->
|
||||||
case get_env_config() of
|
unicode:characters_to_binary(
|
||||||
{ok, Path} ->
|
case get_env_config() of
|
||||||
Path;
|
{ok, Path} ->
|
||||||
undefined ->
|
Path;
|
||||||
case os:getenv("EJABBERD_CONFIG_PATH") of
|
undefined ->
|
||||||
false ->
|
case os:getenv("EJABBERD_CONFIG_PATH") of
|
||||||
"ejabberd.yml";
|
false ->
|
||||||
Path ->
|
"ejabberd.yml";
|
||||||
Path
|
Path ->
|
||||||
end
|
Path
|
||||||
end.
|
end
|
||||||
|
end).
|
||||||
|
|
||||||
-spec get_env_config() -> {ok, string()} | undefined.
|
-spec get_env_config() -> {ok, string()} | undefined.
|
||||||
get_env_config() ->
|
get_env_config() ->
|
||||||
@ -456,12 +459,13 @@ validators(Mod, Disallowed) ->
|
|||||||
end
|
end
|
||||||
end, proplists:get_keys(Mod:options()))).
|
end, proplists:get_keys(Mod:options()))).
|
||||||
|
|
||||||
-spec get_modules_configs() -> [file:filename_all()].
|
-spec get_modules_configs() -> [binary()].
|
||||||
get_modules_configs() ->
|
get_modules_configs() ->
|
||||||
Fs = [{filename:rootname(filename:basename(F)), F}
|
Fs = [{filename:rootname(filename:basename(F)), F}
|
||||||
|| F <- filelib:wildcard(ext_mod:config_dir() ++ "/*.{yml,yaml}")
|
|| F <- filelib:wildcard(ext_mod:config_dir() ++ "/*.{yml,yaml}")
|
||||||
++ filelib:wildcard(ext_mod:modules_dir() ++ "/*/conf/*.{yml,yaml}")],
|
++ filelib:wildcard(ext_mod:modules_dir() ++ "/*/conf/*.{yml,yaml}")],
|
||||||
[proplists:get_value(F, Fs) || F <- proplists:get_keys(Fs)].
|
[unicode:characters_to_binary(proplists:get_value(F, Fs))
|
||||||
|
|| F <- proplists:get_keys(Fs)].
|
||||||
|
|
||||||
read_file(File) ->
|
read_file(File) ->
|
||||||
read_file(File, [replace_macros, include_files, include_modules_configs]).
|
read_file(File, [replace_macros, include_files, include_modules_configs]).
|
||||||
@ -469,7 +473,7 @@ read_file(File) ->
|
|||||||
read_file(File, Opts) ->
|
read_file(File, Opts) ->
|
||||||
{Opts1, Opts2} = proplists:split(Opts, [replace_macros, include_files]),
|
{Opts1, Opts2} = proplists:split(Opts, [replace_macros, include_files]),
|
||||||
Ret = case filename:extension(File) of
|
Ret = case filename:extension(File) of
|
||||||
Ex when Ex == ".yml" orelse Ex == ".yaml" ->
|
Ex when Ex == <<".yml">> orelse Ex == <<".yaml">> ->
|
||||||
Files = case proplists:get_bool(include_modules_configs, Opts2) of
|
Files = case proplists:get_bool(include_modules_configs, Opts2) of
|
||||||
true -> get_modules_configs();
|
true -> get_modules_configs();
|
||||||
false -> []
|
false -> []
|
||||||
@ -549,7 +553,7 @@ pre_validate(Y1) ->
|
|||||||
Err
|
Err
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec load_file(file:filename_all()) -> ok | error_return().
|
-spec load_file(binary()) -> ok | error_return().
|
||||||
load_file(File) ->
|
load_file(File) ->
|
||||||
try
|
try
|
||||||
case read_file(File) of
|
case read_file(File) of
|
||||||
|
Loading…
Reference in New Issue
Block a user