summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_prv_update.erl28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl
index 0491535..6637ebe 100644
--- a/src/rebar_prv_update.erl
+++ b/src/rebar_prv_update.erl
@@ -44,24 +44,28 @@ do(State) ->
TmpFile = filename:join(TmpDir, "packages.gz"),
Url = rebar_state:get(State, rebar_packages_cdn, ?DEFAULT_HEX_REGISTRY),
- {ok, _RequestId} = httpc:request(get, {Url, []},
- [], [{stream, TmpFile}, {sync, true}],
- rebar),
- {ok, Data} = file:read_file(TmpFile),
- Unzipped = zlib:gunzip(Data),
- ok = file:write_file(HexFile, Unzipped),
- ?INFO("Writing registry to ~s", [HexFile]),
- hex_to_index(State),
- ok
+ case httpc:request(get, {Url, []},
+ [], [{stream, TmpFile}, {sync, true}],
+ rebar) of
+ {ok, saved_to_file} ->
+ {ok, Data} = file:read_file(TmpFile),
+ Unzipped = zlib:gunzip(Data),
+ ok = file:write_file(HexFile, Unzipped),
+ ?INFO("Writing registry to ~s", [HexFile]),
+ hex_to_index(State),
+ {ok, State};
+ _ ->
+ ?PRV_ERROR(package_index_download)
+ end
catch
_E:C ->
?DEBUG("Error creating package index: ~p ~p", [C, erlang:get_stacktrace()]),
throw(?PRV_ERROR(package_index_write))
- end,
-
- {ok, State}.
+ end.
-spec format_error(any()) -> iolist().
+format_error(package_index_download) ->
+ "Failed to download package index.";
format_error(package_index_write) ->
"Failed to write package index.".