Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deps/rabbit/src/rabbit_definitions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 29 additions & 21 deletions deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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).

%%
Expand Down Expand Up @@ -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.