@@ -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 ;
7062load (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 );
114106load_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
208201load_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