Skip to content

Commit

Permalink
Merge pull request #3313 from esl/remove-required-files
Browse files Browse the repository at this point in the history
Remove the unused check for required_files
  • Loading branch information
vkatsuba authored Oct 4, 2021
2 parents a85ac5a + 2db91ba commit 2352d22
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
7 changes: 0 additions & 7 deletions src/config/mongoose_config_parser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
state_to_hosts/1,
state_to_host_types/1,
state_to_global_opt/3,
state_to_required_files/1,
can_override/2]).

%% config post-processing
Expand Down Expand Up @@ -143,12 +142,6 @@ state_to_global_opt(OptName, State, Default) ->
Opts = state_to_opts(State),
opts_to_global_opt(Opts, OptName, Default).

%% @doc Files, that are required to be present on disc.
-spec state_to_required_files(state()) -> list(file:filename()).
state_to_required_files(State) ->
Opts = state_to_opts(State),
opts_to_global_opt(Opts, required_files, []).

opts_to_global_opt([{config, OptName, OptValue}|_], OptName, _Default) ->
OptValue;
opts_to_global_opt([_|Opts], OptName, Default) ->
Expand Down
33 changes: 2 additions & 31 deletions src/ejabberd_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ get_config_path() ->
-spec load_file(File :: string()) -> ok.
load_file(File) ->
State = mongoose_config_parser:parse_file(File),
assert_required_files_exist(State),
set_opts(State).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -277,23 +276,14 @@ get_categorized_options() ->
local_config => get_local_config(),
host_config => get_host_local_config()}.

%% @doc Returns configs on disc and in memory for this node.
%% This function prepares all state data to pass into pure code part
%% (i.e. mongoose_config_parser).
%% @doc Returns configs on disc and in memory for this node for inspection.
config_state() ->
ConfigFile = get_config_path(),
State = mongoose_config_parser:parse_file(ConfigFile),
%% Performance optimization hint:
%% terms_to_missing_and_required_files/1 actually parses Terms into State.
#{missing_files := MissingFiles,
required_files := RequiredFiles} =
state_to_missing_and_required_files(State),
#{mongoose_node => node(),
config_file => ConfigFile,
loaded_categorized_options => get_categorized_options(),
ondisc_config_state => State,
missing_files => MissingFiles,
required_files => RequiredFiles}.
ondisc_config_state => State}.

config_states() ->
config_states(all_cluster_nodes()).
Expand Down Expand Up @@ -322,22 +312,3 @@ other_cluster_nodes() ->
is_mongooseim_node(Node) ->
Apps = rpc:call(Node, application, which_applications, []),
lists:keymember(mongooseim, 1, Apps).

assert_required_files_exist(State) ->
RequiredFiles = mongoose_config_parser:state_to_required_files(State),
case missing_files(RequiredFiles) of
[] ->
ok;
MissingFiles ->
erlang:error(#{issue => missing_files,
filenames => MissingFiles})
end.

state_to_missing_and_required_files(State) ->
RequiredFiles = mongoose_config_parser:state_to_required_files(State),
MissingFiles = missing_files(RequiredFiles),
#{missing_files => MissingFiles, required_files => RequiredFiles}.

missing_files(RequiredFiles) ->
[Filename || Filename <- RequiredFiles,
not mongoose_config_utils:is_file_readable(Filename)].

0 comments on commit 2352d22

Please sign in to comment.