summaryrefslogtreecommitdiff
path: root/src/rebar_packages.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_packages.erl')
-rw-r--r--src/rebar_packages.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl
new file mode 100644
index 0000000..103d3a3
--- /dev/null
+++ b/src/rebar_packages.erl
@@ -0,0 +1,23 @@
+-module(rebar_packages).
+
+-export([get_packages/1]).
+
+-include("rebar.hrl").
+
+-spec get_packages(rebar_state:t()) -> {list(), rlx_depsolver:t()}.
+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),
+ binary_to_term(Binary)
+ catch
+ _:_ ->
+ ?ERROR("Bad packages index, try to fix with `rebar update`~n", []),
+ {[], rlx_depsolver:new()}
+ end;
+ false ->
+ {[], rlx_depsolver:new()}
+ end.