mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Merge pull request #90 from smarkets/upgrade-fixes
look for new and old versions in the target parent
This commit is contained in:
commit
18d4ddc8d0
4 changed files with 138 additions and 107 deletions
|
@ -40,11 +40,15 @@
|
||||||
|
|
||||||
'generate-appups'(_Config, ReltoolFile) ->
|
'generate-appups'(_Config, ReltoolFile) ->
|
||||||
%% Get the old release path
|
%% Get the old release path
|
||||||
OldVerPath = rebar_rel_utils:get_previous_release_path(),
|
ReltoolConfig = rebar_rel_utils:load_config(ReltoolFile),
|
||||||
|
TargetParentDir = rebar_rel_utils:get_target_parent_dir(ReltoolConfig),
|
||||||
|
|
||||||
|
OldVerPath = filename:join([TargetParentDir,
|
||||||
|
rebar_rel_utils:get_previous_release_path()]),
|
||||||
|
|
||||||
%% Get the new and old release name and versions
|
%% Get the new and old release name and versions
|
||||||
{Name, _Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolFile),
|
{Name, _Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolFile),
|
||||||
NewVerPath = filename:join([".", Name]),
|
NewVerPath = filename:join([TargetParentDir, Name]),
|
||||||
{NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NewVerPath),
|
{NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NewVerPath),
|
||||||
{OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
|
{OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
|
||||||
|
|
||||||
|
@ -60,7 +64,7 @@
|
||||||
|
|
||||||
%% Get a list of any appup files that exist in the new release
|
%% Get a list of any appup files that exist in the new release
|
||||||
NewAppUpFiles = rebar_utils:find_files(
|
NewAppUpFiles = rebar_utils:find_files(
|
||||||
filename:join([NewName, "lib"]), "^.*.appup$"),
|
filename:join([NewVerPath, "lib"]), "^.*.appup$"),
|
||||||
|
|
||||||
%% Convert the list of appup files into app names
|
%% Convert the list of appup files into app names
|
||||||
AppUpApps = [file_to_name(File) || File <- NewAppUpFiles],
|
AppUpApps = [file_to_name(File) || File <- NewAppUpFiles],
|
||||||
|
@ -69,7 +73,7 @@
|
||||||
UpgradeApps = genappup_which_apps(Upgraded, AppUpApps),
|
UpgradeApps = genappup_which_apps(Upgraded, AppUpApps),
|
||||||
|
|
||||||
%% Generate appup files for upgraded apps
|
%% Generate appup files for upgraded apps
|
||||||
generate_appup_files(Name, OldVerPath, UpgradeApps),
|
generate_appup_files(NewVerPath, OldVerPath, UpgradeApps),
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -124,10 +128,10 @@ genappup_which_apps(UpgradedApps, [First|Rest]) ->
|
||||||
genappup_which_apps(Apps, []) ->
|
genappup_which_apps(Apps, []) ->
|
||||||
Apps.
|
Apps.
|
||||||
|
|
||||||
generate_appup_files(Name, OldVerPath, [{App, {OldVer, NewVer}}|Rest]) ->
|
generate_appup_files(NewVerPath, OldVerPath, [{App, {OldVer, NewVer}}|Rest]) ->
|
||||||
OldEbinDir = filename:join([".", OldVerPath, "lib",
|
OldEbinDir = filename:join([OldVerPath, "lib",
|
||||||
atom_to_list(App) ++ "-" ++ OldVer, "ebin"]),
|
atom_to_list(App) ++ "-" ++ OldVer, "ebin"]),
|
||||||
NewEbinDir = filename:join([".", Name, "lib",
|
NewEbinDir = filename:join([NewVerPath, "lib",
|
||||||
atom_to_list(App) ++ "-" ++ NewVer, "ebin"]),
|
atom_to_list(App) ++ "-" ++ NewVer, "ebin"]),
|
||||||
|
|
||||||
{AddedFiles, DeletedFiles, ChangedFiles} = beam_lib:cmp_dirs(NewEbinDir,
|
{AddedFiles, DeletedFiles, ChangedFiles} = beam_lib:cmp_dirs(NewEbinDir,
|
||||||
|
@ -147,7 +151,7 @@ generate_appup_files(Name, OldVerPath, [{App, {OldVer, NewVer}}|Rest]) ->
|
||||||
OldVer, Inst, OldVer])),
|
OldVer, Inst, OldVer])),
|
||||||
|
|
||||||
?CONSOLE("Generated appup for ~p~n", [App]),
|
?CONSOLE("Generated appup for ~p~n", [App]),
|
||||||
generate_appup_files(Name, OldVerPath, Rest);
|
generate_appup_files(NewVerPath, OldVerPath, Rest);
|
||||||
generate_appup_files(_, _, []) ->
|
generate_appup_files(_, _, []) ->
|
||||||
?CONSOLE("Appup generation complete~n", []).
|
?CONSOLE("Appup generation complete~n", []).
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,11 @@
|
||||||
get_rel_apps/1,
|
get_rel_apps/1,
|
||||||
get_rel_apps/2,
|
get_rel_apps/2,
|
||||||
get_previous_release_path/0,
|
get_previous_release_path/0,
|
||||||
get_rel_file_path/2]).
|
get_rel_file_path/2,
|
||||||
|
load_config/1,
|
||||||
|
get_sys_tuple/1,
|
||||||
|
get_target_dir/1,
|
||||||
|
get_target_parent_dir/1]).
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
|
@ -51,16 +55,11 @@ is_rel_dir(Dir) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Get release name and version from a reltool.config
|
%% Get release name and version from a reltool.config
|
||||||
get_reltool_release_info(ReltoolFile) ->
|
get_reltool_release_info(ReltoolConfig) ->
|
||||||
%% expect sys to be the first proplist in reltool.config
|
|
||||||
case file:consult(ReltoolFile) of
|
|
||||||
{ok, [{sys, Config}| _]} ->
|
|
||||||
%% expect the first rel in the proplist to be the one you want
|
%% expect the first rel in the proplist to be the one you want
|
||||||
|
{sys, Config} = get_sys_tuple(ReltoolConfig),
|
||||||
{rel, Name, Ver, _} = proplists:lookup(rel, Config),
|
{rel, Name, Ver, _} = proplists:lookup(rel, Config),
|
||||||
{Name, Ver};
|
{Name, Ver}.
|
||||||
_ ->
|
|
||||||
?ABORT("Failed to parse ~s~n", [ReltoolFile])
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% Get release name and version from a rel file
|
%% Get release name and version from a rel file
|
||||||
get_rel_release_info(RelFile) ->
|
get_rel_release_info(RelFile) ->
|
||||||
|
@ -107,6 +106,59 @@ get_previous_release_path() ->
|
||||||
OldVerPath
|
OldVerPath
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Load terms from reltool.config
|
||||||
|
%%
|
||||||
|
load_config(ReltoolFile) ->
|
||||||
|
case file:consult(ReltoolFile) of
|
||||||
|
{ok, Terms} ->
|
||||||
|
Terms;
|
||||||
|
Other ->
|
||||||
|
?ABORT("Failed to load expected config from ~s: ~p\n",
|
||||||
|
[ReltoolFile, Other])
|
||||||
|
end.
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Look for the {sys, [...]} tuple in the reltool.config file.
|
||||||
|
%% Without this present, we can't run reltool.
|
||||||
|
%%
|
||||||
|
get_sys_tuple(ReltoolConfig) ->
|
||||||
|
case lists:keyfind(sys, 1, ReltoolConfig) of
|
||||||
|
{sys, _} = SysTuple ->
|
||||||
|
SysTuple;
|
||||||
|
false ->
|
||||||
|
?ABORT("Failed to find {sys, [...]} tuple in reltool.config.", [])
|
||||||
|
end.
|
||||||
|
|
||||||
|
%%
|
||||||
|
%% Look for {target_dir, TargetDir} in the reltool config file; if none is
|
||||||
|
%% found, use the name of the release as the default target directory.
|
||||||
|
%%
|
||||||
|
get_target_dir(ReltoolConfig) ->
|
||||||
|
case rebar_config:get_global(target_dir, undefined) of
|
||||||
|
undefined ->
|
||||||
|
case lists:keyfind(target_dir, 1, ReltoolConfig) of
|
||||||
|
{target_dir, TargetDir} ->
|
||||||
|
filename:absname(TargetDir);
|
||||||
|
false ->
|
||||||
|
{sys, SysInfo} = get_sys_tuple(ReltoolConfig),
|
||||||
|
case lists:keyfind(rel, 1, SysInfo) of
|
||||||
|
{rel, Name, _Vsn, _Apps} ->
|
||||||
|
filename:absname(Name);
|
||||||
|
false ->
|
||||||
|
filename:absname("target")
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
TargetDir ->
|
||||||
|
filename:absname(TargetDir)
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_target_parent_dir(ReltoolConfig) ->
|
||||||
|
case lists:reverse(tl(lists:reverse(filename:split(get_target_dir(ReltoolConfig))))) of
|
||||||
|
[] -> ".";
|
||||||
|
Components -> filename:join(Components)
|
||||||
|
end.
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
|
@ -42,14 +42,16 @@ generate(Config, ReltoolFile) ->
|
||||||
check_vsn(),
|
check_vsn(),
|
||||||
|
|
||||||
%% Load the reltool configuration from the file
|
%% Load the reltool configuration from the file
|
||||||
ReltoolConfig = load_config(ReltoolFile),
|
ReltoolConfig = rebar_rel_utils:load_config(ReltoolFile),
|
||||||
|
|
||||||
|
Sys = rebar_rel_utils:get_sys_tuple(ReltoolConfig),
|
||||||
|
|
||||||
%% Spin up reltool server and load our config into it
|
%% Spin up reltool server and load our config into it
|
||||||
{ok, Server} = reltool:start_server([sys_tuple(ReltoolConfig)]),
|
{ok, Server} = reltool:start_server([Sys]),
|
||||||
|
|
||||||
%% Do some validation of the reltool configuration; error messages out of
|
%% Do some validation of the reltool configuration; error messages out of
|
||||||
%% reltool are still pretty cryptic
|
%% reltool are still pretty cryptic
|
||||||
validate_rel_apps(Server, sys_tuple(ReltoolConfig)),
|
validate_rel_apps(Server, Sys),
|
||||||
|
|
||||||
%% Finally, run reltool
|
%% Finally, run reltool
|
||||||
case catch(run_reltool(Server, Config, ReltoolConfig)) of
|
case catch(run_reltool(Server, Config, ReltoolConfig)) of
|
||||||
|
@ -64,8 +66,8 @@ generate(Config, ReltoolFile) ->
|
||||||
|
|
||||||
|
|
||||||
clean(_Config, ReltoolFile) ->
|
clean(_Config, ReltoolFile) ->
|
||||||
ReltoolConfig = load_config(ReltoolFile),
|
ReltoolConfig = rebar_rel_utils:load_config(ReltoolFile),
|
||||||
TargetDir = target_dir(ReltoolConfig),
|
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||||
rebar_file_utils:rm_rf(TargetDir),
|
rebar_file_utils:rm_rf(TargetDir),
|
||||||
rebar_file_utils:delete_each(["reltool.spec"]).
|
rebar_file_utils:delete_each(["reltool.spec"]).
|
||||||
|
|
||||||
|
@ -91,53 +93,6 @@ check_vsn() ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%
|
|
||||||
%% Load terms from reltool.config
|
|
||||||
%%
|
|
||||||
load_config(ReltoolFile) ->
|
|
||||||
case file:consult(ReltoolFile) of
|
|
||||||
{ok, Terms} ->
|
|
||||||
Terms;
|
|
||||||
Other ->
|
|
||||||
?ABORT("Failed to load expected config from ~s: ~p\n",
|
|
||||||
[ReltoolFile, Other])
|
|
||||||
end.
|
|
||||||
|
|
||||||
%%
|
|
||||||
%% Look for the {sys, [...]} tuple in the reltool.config file.
|
|
||||||
%% Without this present, we can't run reltool.
|
|
||||||
%%
|
|
||||||
sys_tuple(ReltoolConfig) ->
|
|
||||||
case lists:keyfind(sys, 1, ReltoolConfig) of
|
|
||||||
{sys, _} = SysTuple ->
|
|
||||||
SysTuple;
|
|
||||||
false ->
|
|
||||||
?ABORT("Failed to find {sys, [...]} tuple in reltool.config.", [])
|
|
||||||
end.
|
|
||||||
|
|
||||||
%%
|
|
||||||
%% Look for {target_dir, TargetDir} in the reltool config file; if none is
|
|
||||||
%% found, use the name of the release as the default target directory.
|
|
||||||
%%
|
|
||||||
target_dir(ReltoolConfig) ->
|
|
||||||
case rebar_config:get_global(target_dir, undefined) of
|
|
||||||
undefined ->
|
|
||||||
case lists:keyfind(target_dir, 1, ReltoolConfig) of
|
|
||||||
{target_dir, TargetDir} ->
|
|
||||||
filename:absname(TargetDir);
|
|
||||||
false ->
|
|
||||||
{sys, SysInfo} = sys_tuple(ReltoolConfig),
|
|
||||||
case lists:keyfind(rel, 1, SysInfo) of
|
|
||||||
{rel, Name, _Vsn, _Apps} ->
|
|
||||||
filename:absname(Name);
|
|
||||||
false ->
|
|
||||||
filename:absname("target")
|
|
||||||
end
|
|
||||||
end;
|
|
||||||
TargetDir ->
|
|
||||||
filename:absname(TargetDir)
|
|
||||||
end.
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Look for overlay_vars file reference. If the user provides an overlay_vars on
|
%% Look for overlay_vars file reference. If the user provides an overlay_vars on
|
||||||
%% the command line (i.e. a global), the terms from that file OVERRIDE the one
|
%% the command line (i.e. a global), the terms from that file OVERRIDE the one
|
||||||
|
@ -203,7 +158,7 @@ run_reltool(Server, _Config, ReltoolConfig) ->
|
||||||
case reltool:get_target_spec(Server) of
|
case reltool:get_target_spec(Server) of
|
||||||
{ok, Spec} ->
|
{ok, Spec} ->
|
||||||
%% Pull the target dir and make sure it exists
|
%% Pull the target dir and make sure it exists
|
||||||
TargetDir = target_dir(ReltoolConfig),
|
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||||
mk_target_dir(TargetDir),
|
mk_target_dir(TargetDir),
|
||||||
|
|
||||||
%% Dump the spec, if necessary
|
%% Dump the spec, if necessary
|
||||||
|
|
|
@ -38,29 +38,34 @@
|
||||||
|
|
||||||
'generate-upgrade'(_Config, ReltoolFile) ->
|
'generate-upgrade'(_Config, ReltoolFile) ->
|
||||||
%% Get the old release path
|
%% Get the old release path
|
||||||
OldVerPath = rebar_rel_utils:get_previous_release_path(),
|
ReltoolConfig = rebar_rel_utils:load_config(ReltoolFile),
|
||||||
|
TargetParentDir = rebar_rel_utils:get_target_parent_dir(ReltoolConfig),
|
||||||
|
TargetDir = rebar_rel_utils:get_target_dir(ReltoolConfig),
|
||||||
|
|
||||||
|
OldVerPath = filename:join([TargetParentDir,
|
||||||
|
rebar_rel_utils:get_previous_release_path()]),
|
||||||
|
|
||||||
%% Run checks to make sure that building a package is possible
|
%% Run checks to make sure that building a package is possible
|
||||||
{NewName, NewVer} = run_checks(OldVerPath, ReltoolFile),
|
{NewVerPath, NewName, NewVer} = run_checks(OldVerPath, ReltoolConfig),
|
||||||
NameVer = NewName ++ "_" ++ NewVer,
|
NameVer = NewName ++ "_" ++ NewVer,
|
||||||
|
|
||||||
%% Save the code path prior to doing anything
|
%% Save the code path prior to doing anything
|
||||||
OrigPath = code:get_path(),
|
OrigPath = code:get_path(),
|
||||||
|
|
||||||
%% Prepare the environment for building the package
|
%% Prepare the environment for building the package
|
||||||
ok = setup(OldVerPath, NewName, NewVer, NameVer),
|
ok = setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer),
|
||||||
|
|
||||||
%% Build the package
|
%% Build the package
|
||||||
run_systools(NameVer, NewName),
|
run_systools(NameVer, NewName),
|
||||||
|
|
||||||
%% Boot file changes
|
%% Boot file changes
|
||||||
{ok, _} = boot_files(NewVer, NewName),
|
{ok, _} = boot_files(TargetDir, NewVer, NewName),
|
||||||
|
|
||||||
%% Extract upgrade and tar it back up with changes
|
%% Extract upgrade and tar it back up with changes
|
||||||
make_tar(NameVer),
|
make_tar(NameVer),
|
||||||
|
|
||||||
%% Clean up files that systools created
|
%% Clean up files that systools created
|
||||||
ok = cleanup(NameVer, NewName, NewVer),
|
ok = cleanup(NameVer),
|
||||||
|
|
||||||
%% Restore original path
|
%% Restore original path
|
||||||
true = code:set_path(OrigPath),
|
true = code:set_path(OrigPath),
|
||||||
|
@ -71,18 +76,19 @@
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ==================================================================
|
%% ==================================================================
|
||||||
|
|
||||||
run_checks(OldVerPath, ReltoolFile) ->
|
run_checks(OldVerPath, ReltoolConfig) ->
|
||||||
true = rebar_utils:prop_check(filelib:is_dir(OldVerPath),
|
true = rebar_utils:prop_check(filelib:is_dir(OldVerPath),
|
||||||
"Release directory doesn't exist (~p)~n", [OldVerPath]),
|
"Release directory doesn't exist (~p)~n", [OldVerPath]),
|
||||||
|
|
||||||
{Name, Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolFile),
|
{Name, Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolConfig),
|
||||||
|
|
||||||
NamePath = filename:join([".", Name]),
|
NewVerPath = filename:join([
|
||||||
true = rebar_utils:prop_check(filelib:is_dir(NamePath),
|
rebar_rel_utils:get_target_parent_dir(ReltoolConfig),
|
||||||
"Release directory doesn't exist (~p)~n", [NamePath]),
|
Name]),
|
||||||
|
true = rebar_utils:prop_check(filelib:is_dir(NewVerPath),
|
||||||
|
"Release directory doesn't exist (~p)~n", [NewVerPath]),
|
||||||
|
|
||||||
{NewName, NewVer} = NewNameAndVer =
|
{NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NewVerPath),
|
||||||
rebar_rel_utils:get_rel_release_info(Name, NamePath),
|
|
||||||
{OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
|
{OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
|
||||||
|
|
||||||
true = rebar_utils:prop_check(NewName == OldName,
|
true = rebar_utils:prop_check(NewName == OldName,
|
||||||
|
@ -94,11 +100,10 @@ run_checks(OldVerPath, ReltoolFile) ->
|
||||||
true = rebar_utils:prop_check(Ver == NewVer,
|
true = rebar_utils:prop_check(Ver == NewVer,
|
||||||
"Reltool and .rel versions do not match~n", []),
|
"Reltool and .rel versions do not match~n", []),
|
||||||
|
|
||||||
NewNameAndVer.
|
{NewVerPath, NewName, NewVer}.
|
||||||
|
|
||||||
setup(OldVerPath, NewName, NewVer, NameVer) ->
|
setup(OldVerPath, NewVerPath, NewName, NewVer, NameVer) ->
|
||||||
NewRelPath = filename:join([".", NewName]),
|
Src = filename:join([NewVerPath, "releases",
|
||||||
Src = filename:join([NewRelPath, "releases",
|
|
||||||
NewVer, NewName ++ ".rel"]),
|
NewVer, NewName ++ ".rel"]),
|
||||||
Dst = filename:join([".", NameVer ++ ".rel"]),
|
Dst = filename:join([".", NameVer ++ ".rel"]),
|
||||||
{ok, _} = file:copy(Src, Dst),
|
{ok, _} = file:copy(Src, Dst),
|
||||||
|
@ -108,9 +113,9 @@ setup(OldVerPath, NewName, NewVer, NameVer) ->
|
||||||
"releases", "*"])),
|
"releases", "*"])),
|
||||||
filelib:wildcard(filename:join([OldVerPath,
|
filelib:wildcard(filename:join([OldVerPath,
|
||||||
"lib", "*", "ebin"])),
|
"lib", "*", "ebin"])),
|
||||||
filelib:wildcard(filename:join([NewRelPath,
|
filelib:wildcard(filename:join([NewVerPath,
|
||||||
"lib", "*", "ebin"])),
|
"lib", "*", "ebin"])),
|
||||||
filelib:wildcard(filename:join([NewRelPath, "*"]))
|
filelib:wildcard(filename:join([NewVerPath, "*"]))
|
||||||
])).
|
])).
|
||||||
|
|
||||||
run_systools(NewVer, Name) ->
|
run_systools(NewVer, Name) ->
|
||||||
|
@ -135,30 +140,35 @@ run_systools(NewVer, Name) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
boot_files(Ver, Name) ->
|
boot_files(TargetDir, Ver, Name) ->
|
||||||
ok = file:make_dir(filename:join([".", "releases"])),
|
Tmp = "_tmp",
|
||||||
ok = file:make_dir(filename:join([".", "releases", Ver])),
|
ok = file:make_dir(filename:join([".", Tmp])),
|
||||||
|
ok = file:make_dir(filename:join([".", Tmp, "releases"])),
|
||||||
|
ok = file:make_dir(filename:join([".", Tmp, "releases", Ver])),
|
||||||
ok = file:make_symlink(
|
ok = file:make_symlink(
|
||||||
filename:join(["start.boot"]),
|
filename:join(["start.boot"]),
|
||||||
filename:join([".", "releases", Ver, Name ++ ".boot"])),
|
filename:join([".", Tmp, "releases", Ver, Name ++ ".boot"])),
|
||||||
{ok, _} = file:copy(
|
{ok, _} = file:copy(
|
||||||
filename:join([".", Name, "releases", Ver, "start_clean.boot"]),
|
filename:join([TargetDir, "releases", Ver, "start_clean.boot"]),
|
||||||
filename:join([".", "releases", Ver, "start_clean.boot"])).
|
filename:join([".", Tmp, "releases", Ver, "start_clean.boot"])).
|
||||||
|
|
||||||
make_tar(NameVer) ->
|
make_tar(NameVer) ->
|
||||||
Filename = NameVer ++ ".tar.gz",
|
Filename = NameVer ++ ".tar.gz",
|
||||||
ok = erl_tar:extract(Filename, [compressed]),
|
{ok, Cwd} = file:get_cwd(),
|
||||||
ok = file:delete(Filename),
|
Absname = filename:join([Cwd, Filename]),
|
||||||
{ok, Tar} = erl_tar:open(Filename, [write, compressed]),
|
ok = file:set_cwd("_tmp"),
|
||||||
|
ok = erl_tar:extract(Absname, [compressed]),
|
||||||
|
ok = file:delete(Absname),
|
||||||
|
{ok, Tar} = erl_tar:open(Absname, [write, compressed]),
|
||||||
ok = erl_tar:add(Tar, "lib", []),
|
ok = erl_tar:add(Tar, "lib", []),
|
||||||
ok = erl_tar:add(Tar, "releases", []),
|
ok = erl_tar:add(Tar, "releases", []),
|
||||||
ok = erl_tar:close(Tar),
|
ok = erl_tar:close(Tar),
|
||||||
|
ok = file:set_cwd(Cwd),
|
||||||
?CONSOLE("~s upgrade package created~n", [NameVer]).
|
?CONSOLE("~s upgrade package created~n", [NameVer]).
|
||||||
|
|
||||||
cleanup(NameVer, Name, Ver) ->
|
cleanup(NameVer) ->
|
||||||
?DEBUG("Removing files needed for building the upgrade~n", []),
|
?DEBUG("Removing files needed for building the upgrade~n", []),
|
||||||
Files = [
|
Files = [
|
||||||
filename:join([".", "releases", Ver, Name ++ ".boot"]),
|
|
||||||
filename:join([".", NameVer ++ ".rel"]),
|
filename:join([".", NameVer ++ ".rel"]),
|
||||||
filename:join([".", NameVer ++ ".boot"]),
|
filename:join([".", NameVer ++ ".boot"]),
|
||||||
filename:join([".", NameVer ++ ".script"]),
|
filename:join([".", NameVer ++ ".script"]),
|
||||||
|
@ -166,18 +176,17 @@ cleanup(NameVer, Name, Ver) ->
|
||||||
],
|
],
|
||||||
lists:foreach(fun(F) -> ok = file:delete(F) end, Files),
|
lists:foreach(fun(F) -> ok = file:delete(F) end, Files),
|
||||||
|
|
||||||
ok = remove_dir_tree("releases"),
|
ok = remove_dir_tree("_tmp").
|
||||||
ok = remove_dir_tree("lib").
|
|
||||||
|
|
||||||
%% taken from http://www.erlang.org/doc/system_principles/create_target.html
|
%% adapted from http://www.erlang.org/doc/system_principles/create_target.html
|
||||||
remove_dir_tree(Dir) ->
|
remove_dir_tree(Dir) ->
|
||||||
remove_all_files(".", [Dir]).
|
remove_all_files(".", [Dir]).
|
||||||
remove_all_files(Dir, Files) ->
|
remove_all_files(Dir, Files) ->
|
||||||
lists:foreach(fun(File) ->
|
lists:foreach(fun(File) ->
|
||||||
FilePath = filename:join([Dir, File]),
|
FilePath = filename:join([Dir, File]),
|
||||||
{ok, FileInfo} = file:read_file_info(FilePath),
|
{ok, FileInfo, Link} = file_info(FilePath),
|
||||||
case FileInfo#file_info.type of
|
case {Link, FileInfo#file_info.type} of
|
||||||
directory ->
|
{false, directory} ->
|
||||||
{ok, DirFiles} = file:list_dir(FilePath),
|
{ok, DirFiles} = file:list_dir(FilePath),
|
||||||
remove_all_files(FilePath, DirFiles),
|
remove_all_files(FilePath, DirFiles),
|
||||||
file:del_dir(FilePath);
|
file:del_dir(FilePath);
|
||||||
|
@ -185,3 +194,14 @@ remove_all_files(Dir, Files) ->
|
||||||
file:delete(FilePath)
|
file:delete(FilePath)
|
||||||
end
|
end
|
||||||
end, Files).
|
end, Files).
|
||||||
|
|
||||||
|
file_info(Path) ->
|
||||||
|
case file:read_file_info(Path) of
|
||||||
|
{ok, Info} ->
|
||||||
|
{ok, Info, false};
|
||||||
|
{error, enoent} ->
|
||||||
|
{ok, Info} = file:read_link_info(Path),
|
||||||
|
{ok, Info, true};
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in a new issue