Fix upgrade error

This commit is contained in:
terrencehan 2014-06-19 11:08:23 +08:00
parent 24ce11c381
commit a17ee35004
3 changed files with 42 additions and 9 deletions

View file

@ -35,6 +35,7 @@
get_rel_apps/2,
get_previous_release_path/1,
get_rel_file_path/2,
get_rel_file_path/3,
load_config/2,
get_sys_tuple/1,
get_excl_lib_tuple/1,
@ -106,9 +107,18 @@ get_rel_apps(Name, Path) ->
%% Get rel file path from name and path
get_rel_file_path(Name, Path) ->
[RelFile] = filelib:wildcard(filename:join([Path, "releases", "*",
Name ++ ".rel"])),
RelFile.
PVer = get_permanent_version(Path),
get_rel_file_path(Name, Path, PVer).
get_rel_file_path(Name, Path, Version) ->
Dir = filename:join([Path, "releases", Version]),
Path1 = filename:join([Dir, Name ++ "_" ++ Version ++".rel"]),
Path2 = filename:join([Dir, Name ++ ".rel"]),
case {filelib:is_file(Path1), filelib:is_file(Path2)} of
{true, _} -> Path1;
{_, true} -> Path2;
_ -> ?ABORT("can not find .rel file for version ~p", [Version])
end.
%% Get the previous release path from a global variable
get_previous_release_path(Config) ->
@ -244,3 +254,16 @@ expand_rel_version(Config, {rel, Name, Version, Apps}, Dir) ->
{NewConfig, {rel, Name, VsnString, Apps}};
expand_rel_version(Config, Other, _Dir) ->
{Config, Other}.
%% get permanent version from start_erl.data
get_permanent_version(Path) ->
DataFile = filename:join([Path, "releases", "start_erl.data"]),
case file:read_file(DataFile) of
{ok, DataBin} ->
[_, Version] = string:tokens(
string:strip(binary_to_list(DataBin), right, $\n),
" "),
Version;
{error, enoent} ->
?ABORT("start_erl.data is missing", [])
end.

View file

@ -52,9 +52,10 @@
OldVerPath = filename:join([TargetParentDir, PrevRelPath]),
%% Run checks to make sure that building a package is possible
{NewVerPath, NewName, NewVer} = run_checks(Config, OldVerPath,
{NewVerPath, NewName, NewVer, OldVer} = run_checks(Config, OldVerPath,
ReltoolConfig),
NameVer = NewName ++ "_" ++ NewVer,
OldRelName = get_old_rel_name(OldVerPath, OldVer, NewName),
%% Save the code path prior to doing anything
OrigPath = code:get_path(),
@ -63,7 +64,7 @@
ok = setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer),
%% Build the package
run_systools(NameVer, NewName),
run_systools(NameVer, OldRelName),
%% Boot file changes
{ok, _} = boot_files(TargetDir, NewVer, NewName),
@ -122,7 +123,7 @@ run_checks(Config, OldVerPath, ReltoolConfig) ->
rebar_utils:prop_check(Ver == NewVer,
"Reltool and .rel versions do not match~n", []),
{NewVerPath, NewName, NewVer}.
{NewVerPath, NewName, NewVer, OldVer}.
setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
Src = filename:join([NewVerPath, "releases",
@ -139,9 +140,9 @@ setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
"lib", "*", "ebin"]))
])).
run_systools(NewVer, Name) ->
run_systools(NewVer, OldRelName) ->
Opts = [silent],
NameList = [Name],
NameList = [OldRelName],
case systools:make_relup(NewVer, NameList, NameList, Opts) of
{error, _, Msg} ->
?ABORT("Systools [systools:make_relup/4] aborted with: ~p~n",
@ -264,3 +265,7 @@ file_info(Path) ->
Error ->
Error
end.
get_old_rel_name(OldVerPath, OldVer, Name) ->
OldRelFile = rebar_rel_utils:get_rel_file_path(Name, OldVerPath, OldVer),
filename:basename(OldRelFile, ".rel").

View file

@ -38,3 +38,8 @@
erl> release_handler:which_releases().
erl> dummy_server:get_state().
#### Building version 0.3
rm -r rel/dummy
# Now repeat steps in 'Building version 0.2' and 'Deploying with release_handler'