summaryrefslogtreecommitdiff
path: root/src/rebar_packages.erl
blob: b3a7542e7add03ef06cdd82f7d9a9217e283973f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-module(rebar_packages).

-export([get_packages/1]).

-include("rebar.hrl").

-spec get_packages(rebar_state:t()) -> {rebar_dict(), tuple()}.
get_packages(State) ->
    RebarDir = rebar_state:get(State, global_rebar_dir, filename:join(os:getenv("HOME"), ".rebar")),
    PackagesFile = filename:join(RebarDir, "packages"),
    case ec_file:exists(PackagesFile) of
        true ->
            try
                {ok, Binary} = file:read_file(PackagesFile),
                {List, Graph} = binary_to_term(Binary),
                {List, Graph}
            catch
                _:_ ->
                    ?ERROR("Bad packages index, try to fix with `rebar update`~n", []),
                    {[], rlx_depsolver:new_graph()}
            end;
        false ->
            {[], rlx_depsolver:new_graph()}
    end.