diff options
author | Anthony Molinaro <[email protected]> | 2017-05-08 19:04:36 +0000 |
---|---|---|
committer | Anthony Molinaro <[email protected]> | 2017-05-08 19:04:36 +0000 |
commit | 4f8f6125b3769e1eb107b4f02c2f039965688b08 (patch) | |
tree | 8052c9ec2feb58afa88b0f36bc7522da2cdcaac0 /src/rlx_prv_overlay.erl | |
parent | c1e37960af7dc23513f7c6dbc8d711dc30050e84 (diff) | |
download | relx-4f8f6125b3769e1eb107b4f02c2f039965688b08.tar.gz relx-4f8f6125b3769e1eb107b4f02c2f039965688b08.tar.bz2 relx-4f8f6125b3769e1eb107b4f02c2f039965688b08.zip |
Add the ability to chmod files in the overlay.
Two types are supported, direct chmoding, like
{chmod, 8#00700, "path/to/file/maybe/with/{{templates}}" }
or templating the permission where you have a template var like
{file_perm, 8#00700}
and an overlay
{chmod, "{{file_perm}}","path/to/file/maybe/with/{{templates}}" }
Diffstat (limited to 'src/rlx_prv_overlay.erl')
-rw-r--r-- | src/rlx_prv_overlay.erl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl index a4c0fa4..dc57326 100644 --- a/src/rlx_prv_overlay.erl +++ b/src/rlx_prv_overlay.erl @@ -308,6 +308,28 @@ handle_errors(State, Result) -> -spec do_individual_overlay(rlx_state:t(), list(), proplists:proplist(), OverlayDirective::term()) -> {ok, rlx_state:t()} | relx:error(). +do_individual_overlay(State, _Files, OverlayVars, {chmod, Mode, Path}) -> + % mode can be specified directly as an integer value, or if it is + % not an integer we assume it's a template, which we render and convert + % blindly to an integer. So this will crash with an exception if for + % some reason something other than an integer is used + NewMode = + case is_integer(Mode) of + true -> Mode; + false -> erlang:list_to_integer(erlang:binary_to_list(render_string (OverlayVars, Mode))) + end, + + Root = rlx_state:output_dir(State), + file_render_do(OverlayVars, Path, + fun(NewPath) -> + Absolute = absolutize(State, + filename:join(Root,erlang:iolist_to_binary (NewPath))), + case file:change_mode(Absolute, NewMode) of + {error, Error} -> + ?RLX_ERROR({unable_to_chmod, NewMode, NewPath, Error}); + ok -> ok + end + end); do_individual_overlay(State, _Files, OverlayVars, {mkdir, Dir}) -> case rlx_util:render(erlang:iolist_to_binary(Dir), OverlayVars) of {ok, IoList} -> |