Skip to content

Commit

Permalink
move local install/upgrade to 'unstable install/upgrade' and print er…
Browse files Browse the repository at this point in the history
…ror if windows
  • Loading branch information
tsloughter committed Sep 10, 2015
1 parent da3d8a6 commit 6388b30
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
18 changes: 12 additions & 6 deletions src/rebar_prv_local_install.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-include_lib("kernel/include/file.hrl").

-define(PROVIDER, install).
-define(NAMESPACE, local).
-define(NAMESPACE, unstable).
-define(DEPS, []).

%% ===================================================================
Expand All @@ -39,12 +39,18 @@ init(State) ->

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
case rebar_state:escript_path(State) of
undefined ->
?INFO("Already running from an unpacked rebar3. Nothing to do...", []),
case os:type() of
{win32, _} ->
?ERROR("Sorry, this feature is not yet available on Windows."),
{ok, State};
ScriptPath ->
extract_escript(State, ScriptPath)
_ ->
case rebar_state:escript_path(State) of
undefined ->
?INFO("Already running from an unpacked rebar3. Nothing to do...", []),
{ok, State};
ScriptPath ->
extract_escript(State, ScriptPath)
end
end.

-spec format_error(any()) -> iolist().
Expand Down
36 changes: 22 additions & 14 deletions src/rebar_prv_local_upgrade.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-include_lib("kernel/include/file.hrl").

-define(PROVIDER, upgrade).
-define(NAMESPACE, local).
-define(NAMESPACE, unstable).
-define(DEPS, []).

%% ===================================================================
Expand All @@ -37,19 +37,24 @@ init(State) ->

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
Md5 = case rebar_state:escript_path(State) of
undefined ->
false;
ScriptPath ->
get_md5(ScriptPath)
end,

case maybe_fetch_rebar3(Md5) of
up_to_date ->
?CONSOLE("No upgrade available", []),
case os:type() of
{win32, _} ->
?ERROR("Sorry, this feature is not yet available on Windows."),
{ok, State};
{saved, TmpRebar3} ->
rebar_prv_local_install:extract_escript(State, TmpRebar3)
_ ->
Md5 = case rebar_state:escript_path(State) of
undefined ->
false;
ScriptPath ->
get_md5(ScriptPath)
end,

case maybe_fetch_rebar3(Md5) of
{saved, TmpRebar3} ->
rebar_prv_local_install:extract_escript(State, TmpRebar3);
_ ->
{ok, State}
end
end.

-spec format_error(any()) -> iolist().
Expand All @@ -67,10 +72,13 @@ get_md5(Rebar3Path) ->
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
case rebar_pkg_resource:request("https://s3.amazonaws.com/rebar3/rebar4", Rebar3Md5) of
{ok, Binary, _ETag} ->
file:write_file(TmpFile, Binary),
{saved, TmpFile};
error ->
?ERROR("Unable to fetch latest rebar3 escript. Please try again later.", []);
_ ->
?CONSOLE("No upgrade available", []),
up_to_date
end.

0 comments on commit 6388b30

Please sign in to comment.