Merge pull request #252 from tuncer/file_utils-errors

file_utils: properly report errors (fix #95)
This commit is contained in:
Jared Morrow 2014-04-24 07:16:39 -06:00
commit 837df64087
3 changed files with 8 additions and 7 deletions

View file

@ -46,7 +46,7 @@ rm_rf(Target) ->
{unix, _} -> {unix, _} ->
EscTarget = escape_spaces(Target), EscTarget = escape_spaces(Target),
{ok, []} = rebar_utils:sh(?FMT("rm -rf ~s", [EscTarget]), {ok, []} = rebar_utils:sh(?FMT("rm -rf ~s", [EscTarget]),
[{use_stdout, false}, return_on_error]), [{use_stdout, false}, abort_on_error]),
ok; ok;
{win32, _} -> {win32, _} ->
Filelist = filelib:wildcard(Target), Filelist = filelib:wildcard(Target),
@ -67,7 +67,7 @@ cp_r(Sources, Dest) ->
SourceStr = string:join(EscSources, " "), SourceStr = string:join(EscSources, " "),
{ok, []} = rebar_utils:sh(?FMT("cp -R ~s \"~s\"", {ok, []} = rebar_utils:sh(?FMT("cp -R ~s \"~s\"",
[SourceStr, Dest]), [SourceStr, Dest]),
[{use_stdout, false}, return_on_error]), [{use_stdout, false}, abort_on_error]),
ok; ok;
{win32, _} -> {win32, _} ->
lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources), lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources),
@ -81,7 +81,7 @@ mv(Source, Dest) ->
EscSource = escape_spaces(Source), EscSource = escape_spaces(Source),
EscDest = escape_spaces(Dest), EscDest = escape_spaces(Dest),
{ok, []} = rebar_utils:sh(?FMT("mv ~s ~s", [EscSource, EscDest]), {ok, []} = rebar_utils:sh(?FMT("mv ~s ~s", [EscSource, EscDest]),
[{use_stdout, false}, return_on_error]), [{use_stdout, false}, abort_on_error]),
ok; ok;
{win32, _} -> {win32, _} ->
{ok, R} = rebar_utils:sh( {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(). -spec log_and_abort(string(), {integer(), string()}) -> no_return().
log_and_abort(Command, {Rc, Output}) -> log_and_abort(Command, {Rc, Output}) ->
?ABORT("~s failed with error: ~w and output:~n~s~n", ?ABORT("sh(~s)~n"
[Command, Rc, Output]). "failed with return code ~w and the following output:~n"
"~s~n", [Command, Rc, Output]).
sh_loop(Port, Fun, Acc) -> sh_loop(Port, Fun, Acc) ->
receive receive

View file

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