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_rel_apps/2,
get_previous_release_path/1, get_previous_release_path/1,
get_rel_file_path/2, get_rel_file_path/2,
get_rel_file_path/3,
load_config/2, load_config/2,
get_sys_tuple/1, get_sys_tuple/1,
get_excl_lib_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 from name and path
get_rel_file_path(Name, Path) -> get_rel_file_path(Name, Path) ->
[RelFile] = filelib:wildcard(filename:join([Path, "releases", "*", PVer = get_permanent_version(Path),
Name ++ ".rel"])), get_rel_file_path(Name, Path, PVer).
RelFile.
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 the previous release path from a global variable
get_previous_release_path(Config) -> get_previous_release_path(Config) ->
@ -244,3 +254,16 @@ expand_rel_version(Config, {rel, Name, Version, Apps}, Dir) ->
{NewConfig, {rel, Name, VsnString, Apps}}; {NewConfig, {rel, Name, VsnString, Apps}};
expand_rel_version(Config, Other, _Dir) -> expand_rel_version(Config, Other, _Dir) ->
{Config, Other}. {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]), OldVerPath = filename:join([TargetParentDir, PrevRelPath]),
%% Run checks to make sure that building a package is possible %% 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), ReltoolConfig),
NameVer = NewName ++ "_" ++ NewVer, NameVer = NewName ++ "_" ++ NewVer,
OldRelName = get_old_rel_name(OldVerPath, OldVer, NewName),
%% Save the code path prior to doing anything %% Save the code path prior to doing anything
OrigPath = code:get_path(), OrigPath = code:get_path(),
@ -63,7 +64,7 @@
ok = setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer), ok = setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer),
%% Build the package %% Build the package
run_systools(NameVer, NewName), run_systools(NameVer, OldRelName),
%% Boot file changes %% Boot file changes
{ok, _} = boot_files(TargetDir, NewVer, NewName), {ok, _} = boot_files(TargetDir, NewVer, NewName),
@ -122,7 +123,7 @@ run_checks(Config, OldVerPath, ReltoolConfig) ->
rebar_utils:prop_check(Ver == NewVer, rebar_utils:prop_check(Ver == NewVer,
"Reltool and .rel versions do not match~n", []), "Reltool and .rel versions do not match~n", []),
{NewVerPath, NewName, NewVer}. {NewVerPath, NewName, NewVer, OldVer}.
setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) -> setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
Src = filename:join([NewVerPath, "releases", Src = filename:join([NewVerPath, "releases",
@ -139,9 +140,9 @@ setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
"lib", "*", "ebin"])) "lib", "*", "ebin"]))
])). ])).
run_systools(NewVer, Name) -> run_systools(NewVer, OldRelName) ->
Opts = [silent], Opts = [silent],
NameList = [Name], NameList = [OldRelName],
case systools:make_relup(NewVer, NameList, NameList, Opts) of case systools:make_relup(NewVer, NameList, NameList, Opts) of
{error, _, Msg} -> {error, _, Msg} ->
?ABORT("Systools [systools:make_relup/4] aborted with: ~p~n", ?ABORT("Systools [systools:make_relup/4] aborted with: ~p~n",
@ -264,3 +265,7 @@ file_info(Path) ->
Error -> Error ->
Error Error
end. 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> release_handler:which_releases().
erl> dummy_server:get_state(). 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'