diff options
author | David Best <[email protected]> | 2015-02-23 08:57:33 -0800 |
---|---|---|
committer | David Best <[email protected]> | 2015-04-01 11:52:22 -0700 |
commit | 8d6a41901c1d59fadb81e6b9ed578784478852de (patch) | |
tree | b72848b6eb61430f4d1a4f4df0bc4c4bb32a2b1d /src | |
parent | de6b6aa7d48a7f1a238cd9667344d3054b184470 (diff) | |
download | relx-8d6a41901c1d59fadb81e6b9ed578784478852de.tar.gz relx-8d6a41901c1d59fadb81e6b9ed578784478852de.tar.bz2 relx-8d6a41901c1d59fadb81e6b9ed578784478852de.zip |
support symbolic link overlays in dev_mode
If dev_mode=true, an overlay action of 'link' will create the target as a
symbolic link, otherwise it will be copied. In any case, the target will be
copied, not linked, in the .tar file.
Diffstat (limited to 'src')
-rw-r--r-- | src/rlx_prv_archive.erl | 6 | ||||
-rw-r--r-- | src/rlx_prv_overlay.erl | 44 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/rlx_prv_archive.erl b/src/rlx_prv_archive.erl index 7ed8f4d..3ed34f8 100644 --- a/src/rlx_prv_archive.erl +++ b/src/rlx_prv_archive.erl @@ -133,7 +133,7 @@ update_tar(State, TempDir, OutputDir, Name, Vsn, ErtsVersion) -> _ -> [{"lib", filename:join(TempDir, "lib")}, {"erts-"++ErtsVersion, filename:join(OutputDir, "erts-"++ErtsVersion)}] - end]++OverlayFiles, [compressed]), + end]++OverlayFiles, [dereference,compressed]), ec_cmd_log:info(rlx_state:log(State), "tarball ~s successfully created!~n", [TarFile]), ec_file:remove(TempDir, [recursive]), @@ -149,6 +149,8 @@ overlay_files(OverlayVars, Overlay, OutputDir) -> {ec_cnv:to_list(File), ec_cnv:to_list(filename:join(OutputDir, File))} end || O <- Overlay, filter(O)]. +to({link, _, To}) -> + To; to({copy, _, To}) -> To; to({mkdir, To}) -> @@ -158,6 +160,8 @@ to({template, _, To}) -> filter({_, _, "bin/"++_}) -> false; +filter({link, _, _}) -> + true; filter({copy, _, _}) -> true; filter({mkdir, _}) -> diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl index cdce915..47b0b3c 100644 --- a/src/rlx_prv_overlay.erl +++ b/src/rlx_prv_overlay.erl @@ -347,6 +347,21 @@ do_individual_overlay(State, OverlayVars, {copy, From, To}) -> copy_to(State, FromFile, ToFile) end) end); +do_individual_overlay(State, OverlayVars, {link, From, To}) -> + case rlx_state:dev_mode(State) of + false -> + do_individual_overlay(State, OverlayVars, {copy, From, To}); + true -> + FromTemplateName = make_template_name("rlx_copy_from_template", From), + ToTemplateName = make_template_name("rlx_copy_to_template", To), + file_render_do(OverlayVars, From, FromTemplateName, + fun(FromFile) -> + file_render_do(OverlayVars, To, ToTemplateName, + fun(ToFile) -> + link_to(State, FromFile, ToFile) + end) + end) + end; do_individual_overlay(State, OverlayVars, {template, From, To}) -> FromTemplateName = make_template_name("rlx_template_from_template", From), ToTemplateName = make_template_name("rlx_template_to_template", To), @@ -395,6 +410,35 @@ copy_to(State, FromFile0, ToFile0) -> ToFile1, Err}) end. +-spec link_to(rlx_state:t(), file:name(), file:name()) -> ok | relx:error(). +link_to(State, FromFile0, ToFile0) -> + RelativeRoot = get_relative_root(State), + ToFile1 = absolutize(State, filename:join(rlx_state:output_dir(State), + erlang:iolist_to_binary(ToFile0))), + + FromFile1 = absolutize(State, filename:join(RelativeRoot, + erlang:iolist_to_binary(FromFile0))), + ToFile2 = case is_directory(ToFile0, ToFile1) of + false -> + filelib:ensure_dir(ToFile1), + ToFile1; + true -> + rlx_util:mkdir_p(ToFile1), + erlang:iolist_to_binary(filename:join(ToFile1, + filename:basename(FromFile1))) + end, + case ec_file:is_symlink(ToFile2) of + true -> file:delete(ToFile2); + false -> ec_file:remove(ToFile2, [recursive]) + end, + case file:make_symlink(FromFile1, ToFile2) of + ok -> ok; + {error, Err} -> + ?RLX_ERROR({link_failed, + FromFile1, + ToFile1, Err}) + end. + get_relative_root(State) -> case rlx_state:config_file(State) of [] -> |