summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <klishinm@vmware.com>2023-03-21 16:28:15 +0400
committerMichael Klishin <klishinm@vmware.com>2023-03-21 16:28:15 +0400
commit7a043daa935568d8612797f8f175ac26bb6940c2 (patch)
tree34f40b88c3ead211af11454c9d15d0ae22d17fd2
parent984619dfe9e59b3494da3ac5850cbc2f128b9825 (diff)
downloadrabbitmq-server-git-7a043daa935568d8612797f8f175ac26bb6940c2.tar.gz
Closes #7685
-rw-r--r--deps/rabbit/src/rabbit_definitions.erl5
-rw-r--r--deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl50
2 files changed, 32 insertions, 23 deletions
diff --git a/deps/rabbit/src/rabbit_definitions.erl b/deps/rabbit/src/rabbit_definitions.erl
index 07161b9e68..dd9e1a763a 100644
--- a/deps/rabbit/src/rabbit_definitions.erl
+++ b/deps/rabbit/src/rabbit_definitions.erl
@@ -264,14 +264,15 @@ maybe_load_definitions_from_local_filesystem(App, Key) ->
{ok, Path} ->
IsDir = filelib:is_dir(Path),
Mod = rabbit_definitions_import_local_filesystem,
+ rabbit_log:debug("Will use module ~ts to import definitions", [Mod]),
case should_skip_if_unchanged() of
false ->
- rabbit_log:debug("Will use module ~ts to import definitions", [Mod]),
+ rabbit_log:debug("Will re-import definitions even if they have not changed"),
Mod:load(IsDir, Path);
true ->
Algo = rabbit_definitions_hashing:hashing_algorithm(),
- rabbit_log:debug("Will use module ~ts to import definitions (if definition file/directory has changed, hashing algo: ~ts)", [Mod, Algo]),
+ rabbit_log:debug("Will import definitions only if definition file/directory has changed, hashing algo: ~ts", [Algo]),
CurrentHash = rabbit_definitions_hashing:stored_global_hash(),
rabbit_log:debug("Previously stored hash value of imported definitions: ~ts...", [binary:part(rabbit_misc:hexify(CurrentHash), 0, 12)]),
case Mod:load_with_hashing(IsDir, Path, CurrentHash, Algo) of
diff --git a/deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl b/deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl
index 82f47a5f7b..a6f38b91a1 100644
--- a/deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl
+++ b/deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl
@@ -51,20 +51,12 @@ load(Proplist) when is_list(Proplist) ->
undefined -> {error, "local definition file path is not configured: local_path is not set"};
Path ->
rabbit_log:debug("Asked to import definitions from a local file or directory at '~ts'", [Path]),
- case file:read_file_info(Path, [raw]) of
- {ok, FileInfo} ->
- %% same check is used by Cuttlefish validation, this is to be extra defensive
- IsReadable = (element(4, FileInfo) == read) or (element(4, FileInfo) == read_write),
- case IsReadable of
- true ->
- load_from_single_file(Path);
- false ->
- Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
- {error, Msg}
- end;
- _ ->
- Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
- {error, {could_not_read_defs, Msg}}
+ IsDir = filelib:is_dir(Path),
+ case IsDir of
+ true ->
+ load_from_local_path(true, Path);
+ false ->
+ load_from_single_file(Path)
end
end;
load(Map) when is_map(Map) ->
@@ -112,6 +104,7 @@ load_from_local_path(true, Dir) ->
rabbit_log:info("Applying definitions from directory ~ts", [Dir]),
load_from_files(file:list_dir(Dir), Dir);
load_from_local_path(false, File) ->
+ rabbit_log:info("Applying definitions from regular file at ~ts", [File]),
load_from_single_file(File).
%%
@@ -207,11 +200,26 @@ load_from_multiple_files([File|Rest]) ->
load_from_single_file(Path) ->
rabbit_log:debug("Will try to load definitions from a local file or directory at '~ts'", [Path]),
- case rabbit_misc:raw_read_file(Path) of
- {ok, Body} ->
- rabbit_log:info("Applying definitions from file at '~ts'", [Path]),
- import_raw(Body);
- {error, E} ->
- rabbit_log:error("Could not read definitions from file at '~ts', error: ~tp", [Path, E]),
- {error, {could_not_read_defs, {Path, E}}}
+
+ case file:read_file_info(Path, [raw]) of
+ {ok, FileInfo} ->
+ %% same check is used by Cuttlefish validation, this is to be extra defensive
+ IsReadable = (element(4, FileInfo) == read) or (element(4, FileInfo) == read_write),
+ case IsReadable of
+ true ->
+ case rabbit_misc:raw_read_file(Path) of
+ {ok, Body} ->
+ rabbit_log:info("Applying definitions from file at '~ts'", [Path]),
+ import_raw(Body);
+ {error, E} ->
+ rabbit_log:error("Could not read definitions from file at '~ts', error: ~tp", [Path, E]),
+ {error, {could_not_read_defs, {Path, E}}}
+ end;
+ false ->
+ Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
+ {error, Msg}
+ end;
+ _ ->
+ Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
+ {error, {could_not_read_defs, Msg}}
end.