Skip to content

Commit

Permalink
Merge pull request #536 from lrascao/fix/downgrade_non_permanent_version
Browse files Browse the repository at this point in the history
Allow upgrade/downgrade from non-permanent versions
  • Loading branch information
tsloughter authored Nov 26, 2016
2 parents 1014374 + 5b59fab commit 7df9a08
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion priv/templates/install_upgrade_escript
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ install({RelName, NameTypeArg, NodeName, Cookie}, Opts) ->
[Version])
end;
permanent ->
?INFO("Release ~s is already installed and set permanent.~n",[Version]);
%% this release is marked permanent, however it might not the
%% one currently running
case current_release_version(TargetNode) of
Version ->
?INFO("Release ~s is already installed, running and set permanent.~n",
[Version]);
CurrentVersion ->
?INFO("Release ~s is the currently running version.~n",
[CurrentVersion]),
check_and_install(TargetNode, Version),
maybe_permafy(TargetNode, RelName, Version, Opts)
end;
{error, Reason} ->
?INFO("Unpack failed: ~p~n",[Reason]),
print_existing_versions(TargetNode),
Expand Down Expand Up @@ -277,6 +288,16 @@ which_releases(TargetNode) ->
R = rpc:call(TargetNode, release_handler, which_releases, [], ?TIMEOUT),
[ {V, S} || {_,V,_, S} <- R ].

%% the running release version is either the only one marked `current´
%% or, if none exists, the one marked `permanent`
current_release_version(TargetNode) ->
R = rpc:call(TargetNode, release_handler, which_releases,
[], ?TIMEOUT),
Versions = [ {S, V} || {_,V,_, S} <- R ],
%% current version takes priority over the permanent
proplists:get_value(current, Versions,
proplists:get_value(permanent, Versions)).

print_existing_versions(TargetNode) ->
VerList = iolist_to_binary([
io_lib:format("* ~s\t~s~n",[V,S])
Expand Down

0 comments on commit 7df9a08

Please sign in to comment.