Skip to content

Commit

Permalink
Ignore mv warnings
Browse files Browse the repository at this point in the history
In some cases, mv will throw a warning, while still moving the files
correctly and returning a 0 return code:

"mv: can't preserve ownership of ... Permission denied".
  • Loading branch information
ddeboer committed Sep 14, 2016
1 parent 0e2b1a1 commit e2c57e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/rebar_file_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ mv(Source, Dest) ->
{unix, _} ->
EscSource = rebar_utils:escape_chars(Source),
EscDest = rebar_utils:escape_chars(Dest),
{ok, []} = rebar_utils:sh(?FMT("mv ~s ~s", [EscSource, EscDest]),
[{use_stdout, false}, abort_on_error]),
ok;
case rebar_utils:sh(?FMT("mv ~s ~s", [EscSource, EscDest]),
[{use_stdout, false}, abort_on_error]) of
{ok, []} ->
ok;
{ok, Warning} ->
?WARN("mv: ~p", [Warning]),
ok
end;
{win32, _} ->
Cmd = case filelib:is_dir(Source) of
true ->
Expand Down
12 changes: 10 additions & 2 deletions test/rebar_file_utils_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
path_from_ancestor/1,
canonical_path/1,
resolve_link/1,
split_dirname/1]).
split_dirname/1,
mv_warning_is_ignored/1]).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
Expand All @@ -27,7 +28,8 @@ all() ->
path_from_ancestor,
canonical_path,
resolve_link,
split_dirname].
split_dirname,
mv_warning_is_ignored].

groups() ->
[{tmpdir, [], [raw_tmpdir, empty_tmpdir, simple_tmpdir, multi_tmpdir]},
Expand Down Expand Up @@ -135,3 +137,9 @@ split_dirname(_Config) ->
?assertEqual({".", "foo"}, rebar_file_utils:split_dirname("foo")),
?assertEqual({"/foo", "bar"}, rebar_file_utils:split_dirname("/foo/bar")),
?assertEqual({"foo", "bar"}, rebar_file_utils:split_dirname("foo/bar")).

mv_warning_is_ignored(_Config) ->
meck:new(rebar_utils, [passthrough]),
meck:expect(rebar_utils, sh, fun("mv ding dong", _) -> {ok, "Warning"} end),
ok = rebar_utils:mv("ding", "dong"),
meck:unload(rebar_utils).

0 comments on commit e2c57e4

Please sign in to comment.