1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
-module(rebar_packages).
-export([get_packages/1]).
-include("rebar.hrl").
-spec get_packages(rebar_state:t()) -> {rebar_dict(), rlx_depsolver:t()}.
get_packages(State) ->
Home = rebar_utils:home_dir(),
RebarDir = rebar_state:get(State, global_rebar_dir, filename:join(Home, ?CONFIG_DIR)),
PackagesFile = filename:join(RebarDir, "packages"),
case ec_file:exists(PackagesFile) of
true ->
try
{ok, Binary} = file:read_file(PackagesFile),
{Dict, Graph} = binary_to_term(Binary),
{Dict, Graph}
catch
_:_ ->
?ERROR("Bad packages index, try to fix with `rebar update`~n", []),
{dict:new(), rlx_depsolver:new_graph()}
end;
false ->
{dict:new(), rlx_depsolver:new_graph()}
end.
|