file_utils: properly report errors (fix #95)

While at it, improve the error message printed by rebar_utils:sh/2.
This commit is contained in:
Tuncer Ayaz 2014-03-26 18:41:59 +01:00
parent 0c7fe5fc7b
commit e1eec02c80
3 changed files with 8 additions and 7 deletions

View file

@ -46,7 +46,7 @@ rm_rf(Target) ->
{unix, _} ->
EscTarget = escape_spaces(Target),
{ok, []} = rebar_utils:sh(?FMT("rm -rf ~s", [EscTarget]),
[{use_stdout, false}, return_on_error]),
[{use_stdout, false}, abort_on_error]),
ok;
{win32, _} ->
Filelist = filelib:wildcard(Target),
@ -67,7 +67,7 @@ cp_r(Sources, Dest) ->
SourceStr = string:join(EscSources, " "),
{ok, []} = rebar_utils:sh(?FMT("cp -R ~s \"~s\"",
[SourceStr, Dest]),
[{use_stdout, false}, return_on_error]),
[{use_stdout, false}, abort_on_error]),
ok;
{win32, _} ->
lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources),
@ -81,7 +81,7 @@ mv(Source, Dest) ->
EscSource = escape_spaces(Source),
EscDest = escape_spaces(Dest),
{ok, []} = rebar_utils:sh(?FMT("mv ~s ~s", [EscSource, EscDest]),
[{use_stdout, false}, return_on_error]),
[{use_stdout, false}, abort_on_error]),
ok;
{win32, _} ->
{ok, R} = rebar_utils:sh(

View file

@ -398,8 +398,9 @@ log_msg_and_abort(Message) ->
-spec log_and_abort(string(), {integer(), string()}) -> no_return().
log_and_abort(Command, {Rc, Output}) ->
?ABORT("~s failed with error: ~w and output:~n~s~n",
[Command, Rc, Output]).
?ABORT("sh(~s)~n"
"failed with return code ~w and the following output:~n"
"~s~n", [Command, Rc, Output]).
sh_loop(Port, Fun, Acc) ->
receive

View file

@ -191,7 +191,7 @@ cp_r_overwrite_file_fail_test_() ->
filename:join([?TMP_DIR,"dest","file1"]),0)
end,
fun teardown/1,
[?_assertError({badmatch,_},
[?_assertThrow(rebar_abort,
rebar_file_utils:cp_r(
[filename:join([?TMP_DIR,"source","file1"])],
filename:join([?TMP_DIR,"dest"])))]}.
@ -210,7 +210,7 @@ cp_r_overwrite_dir_fail_test_() ->
filename:join([?TMP_DIR,"dest","source","file1"]),0)
end,
fun teardown/1,
[?_assertError({badmatch,_},
[?_assertThrow(rebar_abort,
rebar_file_utils:cp_r(
[filename:join([?TMP_DIR,"source"])],
filename:join([?TMP_DIR,"dest"])))]}.