From c15d99d8bb5f2889e3b1d9f81dc3efbdc6a1e821 Mon Sep 17 00:00:00 2001 From: Matt Campbell Date: Thu, 29 Dec 2011 14:28:03 -0600 Subject: [PATCH] On windows, avoid symlink during upgrade a) make_symlink throws "not supported" on OS < Vista (e.g. 2003) b) tarball creation stores windows symlinks as absolute paths instead of relative, causing service to fail to start after upgrade is made permanent. --- src/rebar_upgrade.erl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl index 8666fe5..3c63a6c 100644 --- a/src/rebar_upgrade.erl +++ b/src/rebar_upgrade.erl @@ -64,7 +64,7 @@ {ok, _} = boot_files(TargetDir, NewVer, NewName), %% Extract upgrade and tar it back up with changes - make_tar(NameVer), + make_tar(NameVer, NewVer, NewName), %% Clean up files that systools created ok = cleanup(NameVer), @@ -149,9 +149,14 @@ boot_files(TargetDir, Ver, Name) -> 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( - filename:join(["start.boot"]), - filename:join([".", ?TMP, "releases", Ver, Name ++ ".boot"])), + case os:type() of + {win32,_} -> + ok; + _ -> + ok = file:make_symlink( + filename:join(["start.boot"]), + filename:join([".", ?TMP, "releases", Ver, Name ++ ".boot"])) + end, {ok, _} = file:copy( filename:join([TargetDir, "releases", Ver, "start_clean.boot"]), @@ -165,13 +170,20 @@ boot_files(TargetDir, Ver, Name) -> filename:join([TargetDir, "releases", Ver, "vm.args"]), filename:join([".", ?TMP, "releases", Ver, "vm.args"])). -make_tar(NameVer) -> +make_tar(NameVer, NewVer, NewName) -> Filename = NameVer ++ ".tar.gz", {ok, Cwd} = file:get_cwd(), Absname = filename:join([Cwd, Filename]), ok = file:set_cwd(?TMP), ok = erl_tar:extract(Absname, [compressed]), ok = file:delete(Absname), + case os:type() of + {win32,_} -> + {ok, _} = file:copy( + filename:join([".", "releases", NewVer, "start.boot"]), + filename:join([".", "releases", NewVer, NewName ++ ".boot"])); + _ -> ok + end, {ok, Tar} = erl_tar:open(Absname, [write, compressed]), ok = erl_tar:add(Tar, "lib", []), ok = erl_tar:add(Tar, "releases", []),