From 1f86ed1aed990438103c5f668c4ec930ab637fc9 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Tue, 4 Oct 2016 22:34:22 -0400 Subject: Track package hash in memory index, add hash test This adds tracking of package hash in the in-memory index rather than the current `undefined' values. According to the test added, this is not necessary for transitive package dep hash chcking, but does result in a more complete index search result when doing app lookups, and could yield some optimizations on hash checks by checking from the index structure before fetching a package. --- src/rebar_prv_update.erl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index ff7194a..75c609e 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -104,7 +104,8 @@ hex_to_index(State) -> case lists:any(fun is_supported/1, BuildTools) of true -> DepsList = update_deps_list(Pkg, PkgVsn, Deps, Registry, State), - ets:insert(?PACKAGE_TABLE, {{Pkg, PkgVsn}, DepsList, Checksum}); + HashedDeps = update_deps_hashes(DepsList), + ets:insert(?PACKAGE_TABLE, {{Pkg, PkgVsn}, HashedDeps, Checksum}); false -> true end; @@ -176,6 +177,21 @@ update_deps_list(Pkg, PkgVsn, Deps, HexRegistry, State) -> DepsListAcc end, [], Deps). +update_deps_hashes(List) -> + [{Name, {pkg, PkgName, Vsn, lookup_hash(PkgName, Vsn, Hash)}} + || {Name, {pkg, PkgName, Vsn, Hash}} <- List]. + +lookup_hash(Name, Vsn, undefined) -> + try + ets:lookup_element(?PACKAGE_TABLE, {Name, Vsn}, 3) + catch + _:_ -> + undefined + end; +lookup_hash(_, _, Hash) -> + Hash. + + rm_ws(<<" ", R/binary>>) -> rm_ws(R); rm_ws(R) -> -- cgit v1.1