From 4f8f6125b3769e1eb107b4f02c2f039965688b08 Mon Sep 17 00:00:00 2001 From: Anthony Molinaro Date: Mon, 8 May 2017 19:04:36 +0000 Subject: 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}}" } --- src/rlx_prv_overlay.erl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') 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} -> -- cgit v1.2.3