summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-09-10 20:43:28 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-09-10 20:43:28 -0400
commitb034a7c3a7d9b4a77e84f6e915963aebe292a141 (patch)
treee2c97f9c5c8049c74cfbc28c47b952973ceedd9d
parenta3a590947ad5fb49c5c8717fb47f03da08e6036c (diff)
parent242d12b234e6e17b09e10d6a209c319353ec7476 (diff)
Merge pull request #792 from tsloughter/checksum_rebar3
check checksum of rebar3 download in local_upgrade provider
-rw-r--r--src/rebar_pkg_resource.erl1
-rw-r--r--src/rebar_prv_local_upgrade.erl18
2 files changed, 15 insertions, 4 deletions
diff --git a/src/rebar_pkg_resource.erl b/src/rebar_pkg_resource.erl
index bff7bc6..f456587 100644
--- a/src/rebar_pkg_resource.erl
+++ b/src/rebar_pkg_resource.erl
@@ -10,6 +10,7 @@
,make_vsn/1]).
-export([request/2
+ ,etag/1
,ssl_opts/1]).
-include("rebar.hrl").
diff --git a/src/rebar_prv_local_upgrade.erl b/src/rebar_prv_local_upgrade.erl
index 9293bc0..bdfc232 100644
--- a/src/rebar_prv_local_upgrade.erl
+++ b/src/rebar_prv_local_upgrade.erl
@@ -10,6 +10,7 @@
format_error/1]).
-include("rebar.hrl").
+-include_lib("providers/include/providers.hrl").
-include_lib("kernel/include/file.hrl").
-define(PROVIDER, upgrade).
@@ -52,12 +53,16 @@ do(State) ->
case maybe_fetch_rebar3(Md5) of
{saved, TmpRebar3} ->
rebar_prv_local_install:extract_escript(State, TmpRebar3);
- _ ->
- {ok, State}
+ up_to_date ->
+ {ok, State};
+ Error ->
+ Error
end
end.
-spec format_error(any()) -> iolist().
+format_error(bad_checksum) ->
+ "Not updating rebar3, the checksum of download did not match the one provided by s3.";
format_error(Reason) ->
io_lib:format("~p", [Reason]).
@@ -73,9 +78,14 @@ maybe_fetch_rebar3(Rebar3Md5) ->
TmpDir = ec_file:insecure_mkdtemp(),
TmpFile = filename:join(TmpDir, "rebar3"),
case rebar_pkg_resource:request("https://s3.amazonaws.com/rebar3/rebar3", Rebar3Md5) of
- {ok, Binary, _ETag} ->
+ {ok, Binary, ETag} ->
file:write_file(TmpFile, Binary),
- {saved, TmpFile};
+ case rebar_pkg_resource:etag(TmpFile) of
+ ETag ->
+ {saved, TmpFile};
+ _ ->
+ ?PRV_ERROR(bad_checksum)
+ end;
error ->
?ERROR("Unable to fetch latest rebar3 escript. Please try again later.", []);
_ ->