diff options
Diffstat (limited to 'src/rebar_file_utils.erl')
-rw-r--r-- | src/rebar_file_utils.erl | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index a3d9b58..fcd9c5e 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -29,7 +29,8 @@ -export([rm_rf/1, cp_r/2, mv/2, - delete_each/1]). + delete_each/1, + write_file_if_contents_differ/2]). -include("rebar.hrl"). @@ -111,6 +112,17 @@ delete_each([File | Rest]) -> ?FAIL end. +write_file_if_contents_differ(Filename, Bytes) -> + ToWrite = iolist_to_binary(Bytes), + case file:read_file(Filename) of + {ok, ToWrite} -> + ok; + {ok, _} -> + file:write_file(Filename, ToWrite); + {error, _} -> + file:write_file(Filename, ToWrite) + end. + %% =================================================================== %% Internal functions %% =================================================================== |