Skip to content

Commit b694cd1

Browse files
Merge pull request #7689 from rabbitmq/rabbitmq-server-7685
Closes #7685
2 parents e93064a + 7a043da commit b694cd1

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,15 @@ maybe_load_definitions_from_local_filesystem(App, Key) ->
264264
{ok, Path} ->
265265
IsDir = filelib:is_dir(Path),
266266
Mod = rabbit_definitions_import_local_filesystem,
267+
rabbit_log:debug("Will use module ~ts to import definitions", [Mod]),
267268

268269
case should_skip_if_unchanged() of
269270
false ->
270-
rabbit_log:debug("Will use module ~ts to import definitions", [Mod]),
271+
rabbit_log:debug("Will re-import definitions even if they have not changed"),
271272
Mod:load(IsDir, Path);
272273
true ->
273274
Algo = rabbit_definitions_hashing:hashing_algorithm(),
274-
rabbit_log:debug("Will use module ~ts to import definitions (if definition file/directory has changed, hashing algo: ~ts)", [Mod, Algo]),
275+
rabbit_log:debug("Will import definitions only if definition file/directory has changed, hashing algo: ~ts", [Algo]),
275276
CurrentHash = rabbit_definitions_hashing:stored_global_hash(),
276277
rabbit_log:debug("Previously stored hash value of imported definitions: ~ts...", [binary:part(rabbit_misc:hexify(CurrentHash), 0, 12)]),
277278
case Mod:load_with_hashing(IsDir, Path, CurrentHash, Algo) of

deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,12 @@ load(Proplist) when is_list(Proplist) ->
5151
undefined -> {error, "local definition file path is not configured: local_path is not set"};
5252
Path ->
5353
rabbit_log:debug("Asked to import definitions from a local file or directory at '~ts'", [Path]),
54-
case file:read_file_info(Path, [raw]) of
55-
{ok, FileInfo} ->
56-
%% same check is used by Cuttlefish validation, this is to be extra defensive
57-
IsReadable = (element(4, FileInfo) == read) or (element(4, FileInfo) == read_write),
58-
case IsReadable of
59-
true ->
60-
load_from_single_file(Path);
61-
false ->
62-
Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
63-
{error, Msg}
64-
end;
65-
_ ->
66-
Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
67-
{error, {could_not_read_defs, Msg}}
54+
IsDir = filelib:is_dir(Path),
55+
case IsDir of
56+
true ->
57+
load_from_local_path(true, Path);
58+
false ->
59+
load_from_single_file(Path)
6860
end
6961
end;
7062
load(Map) when is_map(Map) ->
@@ -112,6 +104,7 @@ load_from_local_path(true, Dir) ->
112104
rabbit_log:info("Applying definitions from directory ~ts", [Dir]),
113105
load_from_files(file:list_dir(Dir), Dir);
114106
load_from_local_path(false, File) ->
107+
rabbit_log:info("Applying definitions from regular file at ~ts", [File]),
115108
load_from_single_file(File).
116109

117110
%%
@@ -207,11 +200,26 @@ load_from_multiple_files([File|Rest]) ->
207200

208201
load_from_single_file(Path) ->
209202
rabbit_log:debug("Will try to load definitions from a local file or directory at '~ts'", [Path]),
210-
case rabbit_misc:raw_read_file(Path) of
211-
{ok, Body} ->
212-
rabbit_log:info("Applying definitions from file at '~ts'", [Path]),
213-
import_raw(Body);
214-
{error, E} ->
215-
rabbit_log:error("Could not read definitions from file at '~ts', error: ~tp", [Path, E]),
216-
{error, {could_not_read_defs, {Path, E}}}
203+
204+
case file:read_file_info(Path, [raw]) of
205+
{ok, FileInfo} ->
206+
%% same check is used by Cuttlefish validation, this is to be extra defensive
207+
IsReadable = (element(4, FileInfo) == read) or (element(4, FileInfo) == read_write),
208+
case IsReadable of
209+
true ->
210+
case rabbit_misc:raw_read_file(Path) of
211+
{ok, Body} ->
212+
rabbit_log:info("Applying definitions from file at '~ts'", [Path]),
213+
import_raw(Body);
214+
{error, E} ->
215+
rabbit_log:error("Could not read definitions from file at '~ts', error: ~tp", [Path, E]),
216+
{error, {could_not_read_defs, {Path, E}}}
217+
end;
218+
false ->
219+
Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
220+
{error, Msg}
221+
end;
222+
_ ->
223+
Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
224+
{error, {could_not_read_defs, Msg}}
217225
end.

0 commit comments

Comments
 (0)