Skip to content

Commit ff4dfc9

Browse files
michaelklishinmergify[bot]
authored andcommitted
Closes #7685
(cherry picked from commit 7a043da) (cherry picked from commit 975dced) # Conflicts: # deps/rabbit/src/rabbit_definitions.erl # deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl
1 parent b8bfb87 commit ff4dfc9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,23 @@ 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 ->
271+
<<<<<<< HEAD
270272
rabbit_log:debug("Will use module ~s to import definitions", [Mod]),
271273
Mod:load(IsDir, Path);
272274
true ->
273275
Algo = rabbit_definitions_hashing:hashing_algorithm(),
274276
rabbit_log:debug("Will use module ~s to import definitions (if definition file/directory has changed, hashing algo: ~s)", [Mod, Algo]),
277+
=======
278+
rabbit_log:debug("Will re-import definitions even if they have not changed"),
279+
Mod:load(IsDir, Path);
280+
true ->
281+
Algo = rabbit_definitions_hashing:hashing_algorithm(),
282+
rabbit_log:debug("Will import definitions only if definition file/directory has changed, hashing algo: ~ts", [Algo]),
283+
>>>>>>> 975dced74c (Closes #7685)
275284
CurrentHash = rabbit_definitions_hashing:stored_global_hash(),
276285
rabbit_log:debug("Previously stored hash value of imported definitions: ~s...", [binary:part(rabbit_misc:hexify(CurrentHash), 0, 12)]),
277286
case Mod:load_with_hashing(IsDir, Path, CurrentHash, Algo) of

deps/rabbit/src/rabbit_definitions_import_local_filesystem.erl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ load(Proplist) when is_list(Proplist) ->
5050
case pget(local_path, Proplist, undefined) of
5151
undefined -> {error, "local definition file path is not configured: local_path is not set"};
5252
Path ->
53+
<<<<<<< HEAD
5354
rabbit_log:debug("Asked to import definitions from a local file or directory at '~s'", [Path]),
5455
case file:read_file_info(Path, [raw]) of
5556
{ok, FileInfo} ->
@@ -65,6 +66,15 @@ load(Proplist) when is_list(Proplist) ->
6566
_ ->
6667
Msg = rabbit_misc:format("local definition file '~s' does not exist or cannot be read by the node", [Path]),
6768
{error, {could_not_read_defs, Msg}}
69+
=======
70+
rabbit_log:debug("Asked to import definitions from a local file or directory at '~ts'", [Path]),
71+
IsDir = filelib:is_dir(Path),
72+
case IsDir of
73+
true ->
74+
load_from_local_path(true, Path);
75+
false ->
76+
load_from_single_file(Path)
77+
>>>>>>> 975dced74c (Closes #7685)
6878
end
6979
end;
7080
load(Map) when is_map(Map) ->
@@ -112,6 +122,7 @@ load_from_local_path(true, Dir) ->
112122
rabbit_log:info("Applying definitions from directory ~s", [Dir]),
113123
load_from_files(file:list_dir(Dir), Dir);
114124
load_from_local_path(false, File) ->
125+
rabbit_log:info("Applying definitions from regular file at ~ts", [File]),
115126
load_from_single_file(File).
116127

117128
%%
@@ -206,6 +217,7 @@ load_from_multiple_files([File|Rest]) ->
206217
end.
207218

208219
load_from_single_file(Path) ->
220+
<<<<<<< HEAD
209221
rabbit_log:debug("Will try to load definitions from a local file or directory at '~s'", [Path]),
210222
case rabbit_misc:raw_read_file(Path) of
211223
{ok, Body} ->
@@ -214,4 +226,29 @@ load_from_single_file(Path) ->
214226
{error, E} ->
215227
rabbit_log:error("Could not read definitions from file at '~s', error: ~p", [Path, E]),
216228
{error, {could_not_read_defs, {Path, E}}}
229+
=======
230+
rabbit_log:debug("Will try to load definitions from a local file or directory at '~ts'", [Path]),
231+
232+
case file:read_file_info(Path, [raw]) of
233+
{ok, FileInfo} ->
234+
%% same check is used by Cuttlefish validation, this is to be extra defensive
235+
IsReadable = (element(4, FileInfo) == read) or (element(4, FileInfo) == read_write),
236+
case IsReadable of
237+
true ->
238+
case rabbit_misc:raw_read_file(Path) of
239+
{ok, Body} ->
240+
rabbit_log:info("Applying definitions from file at '~ts'", [Path]),
241+
import_raw(Body);
242+
{error, E} ->
243+
rabbit_log:error("Could not read definitions from file at '~ts', error: ~tp", [Path, E]),
244+
{error, {could_not_read_defs, {Path, E}}}
245+
end;
246+
false ->
247+
Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
248+
{error, Msg}
249+
end;
250+
_ ->
251+
Msg = rabbit_misc:format("local definition file '~ts' does not exist or cannot be read by the node", [Path]),
252+
{error, {could_not_read_defs, Msg}}
253+
>>>>>>> 975dced74c (Closes #7685)
217254
end.

0 commit comments

Comments
 (0)