Skip to content

Commit

Permalink
Pass a proplist as option argument instead of a boolean
Browse files Browse the repository at this point in the history
The change will help reducing the changes needed if we want
to add more options in the future.
  • Loading branch information
gonzalobf committed Jul 22, 2022
1 parent e19b71f commit 79a1aa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions apps/rebar/src/rebar_file_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,17 @@ rm_rf(Target) ->

-spec cp_r(list(string()), file:filename()) -> 'ok'.
cp_r(Sources, Dest) ->
cp_r(Sources, Dest, false).
cp_r(Sources, Dest, []).

%% @doc Copies files and directories.
%% If Dereference is true, it follows the Sources symbolic link and copies
%% the content
-spec cp_r(list(string()), file:filename(), boolean()) -> 'ok'.
cp_r([], _Dest, _Dereference) ->
%% Options is a proplist with the options to be added to the copy command.
%% It options are:
%% - [{dereference, true|false}]: When true, if the file is a symbolic link
%% it dereferences and copies the original content in Dest
-spec cp_r(list(string()), file:filename(), proplists:proplist()) -> 'ok'.
cp_r([], _Dest, _Options) ->
ok;
cp_r(Sources, Dest, Dereference) ->
cp_r(Sources, Dest, Options) ->
case os:type() of
{unix, Os} ->
EscSources = [rebar_utils:escape_chars(Src) || Src <- Sources],
Expand All @@ -238,13 +240,14 @@ cp_r(Sources, Dest, Dereference) ->
[rebar_utils:escape_chars(Dest)]),
[{use_stdout, false}, abort_on_error]),

Opt = case Dereference of
true -> "-RpL";
false -> "-Rp"
DefaultOptStr = "-Rp",
OptStr = case proplists:get_value(dereference, Options, false) of
true -> DefaultOptStr ++ "L";
false -> DefaultOptStr
end,

{ok, []} = rebar_utils:sh(?FMT("cp ~s ~ts \"~ts\"",
[Opt, Source, rebar_utils:escape_double_quotes(Dest)]),
[OptStr, Source, rebar_utils:escape_double_quotes(Dest)]),
[{use_stdout, true}, abort_on_error]),
ok;
{win32, _} ->
Expand Down
2 changes: 1 addition & 1 deletion apps/rebar/src/rebar_prv_common_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ copy_bare_suites(From, To) ->
DataDirs = lists:filter(fun filelib:is_dir/1,
filelib:wildcard(filename:join([From, "*_SUITE_data"]))),
ok = rebar_file_utils:cp_r(SrcFiles, To),
rebar_file_utils:cp_r(DataDirs, To, true).
rebar_file_utils:cp_r(DataDirs, To, [{dereference, true}]).

maybe_copy_spec(State, [App|Apps], Spec) ->
case rebar_file_utils:path_from_ancestor(filename:dirname(Spec), rebar_app_info:dir(App)) of
Expand Down

0 comments on commit 79a1aa0

Please sign in to comment.