|
@ -36,10 +36,14 @@ |
|
|
write_file_if_contents_differ/2, |
|
|
write_file_if_contents_differ/2, |
|
|
system_tmpdir/0, |
|
|
system_tmpdir/0, |
|
|
system_tmpdir/1, |
|
|
system_tmpdir/1, |
|
|
reset_dir/1]). |
|
|
|
|
|
|
|
|
reset_dir/1, |
|
|
|
|
|
touch/1]). |
|
|
|
|
|
|
|
|
-include("rebar.hrl"). |
|
|
-include("rebar.hrl"). |
|
|
|
|
|
|
|
|
-include_lib("providers/include/providers.hrl"). |
|
|
-include_lib("providers/include/providers.hrl"). |
|
|
|
|
|
-include_lib("kernel/include/file.hrl"). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%% =================================================================== |
|
|
%% =================================================================== |
|
|
%% Public API |
|
|
%% Public API |
|
@ -71,6 +75,11 @@ symlink_or_copy(Source, Target) -> |
|
|
{error, eexist} -> |
|
|
{error, eexist} -> |
|
|
ok; |
|
|
ok; |
|
|
{error, _} -> |
|
|
{error, _} -> |
|
|
|
|
|
Target2 = case is_binary(Target) of |
|
|
|
|
|
true -> unicode:characters_to_list(Target); |
|
|
|
|
|
false -> Target |
|
|
|
|
|
end, |
|
|
|
|
|
rm_rf(Target2), |
|
|
cp_r([Source], Target) |
|
|
cp_r([Source], Target) |
|
|
end. |
|
|
end. |
|
|
|
|
|
|
|
@ -135,7 +144,7 @@ mv(Source, Dest) -> |
|
|
end. |
|
|
end. |
|
|
|
|
|
|
|
|
win32_robocopy_ok({ok, _}) -> true; |
|
|
win32_robocopy_ok({ok, _}) -> true; |
|
|
win32_robocopy_ok({error, {Rc, _}}) when Rc<9, Rc==16 -> true; |
|
|
|
|
|
|
|
|
win32_robocopy_ok({error, {Rc, _}}) when Rc<9; Rc=:=16 -> true; |
|
|
win32_robocopy_ok(_) -> false. |
|
|
win32_robocopy_ok(_) -> false. |
|
|
|
|
|
|
|
|
delete_each([]) -> |
|
|
delete_each([]) -> |
|
@ -189,6 +198,17 @@ reset_dir(Path) -> |
|
|
%% recreate the directory |
|
|
%% recreate the directory |
|
|
filelib:ensure_dir(filename:join([Path, "dummy.beam"])). |
|
|
filelib:ensure_dir(filename:join([Path, "dummy.beam"])). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%% Linux touch but using erlang functions to work in bot *nix os and |
|
|
|
|
|
%% windows |
|
|
|
|
|
-spec touch(Path) -> ok | {error, Reason} when |
|
|
|
|
|
Path :: file:name(), |
|
|
|
|
|
Reason :: file:posix(). |
|
|
|
|
|
touch(Path) -> |
|
|
|
|
|
{ok, A} = file:read_file_info(Path), |
|
|
|
|
|
ok = file:write_file_info(Path, A#file_info{mtime = calendar:local_time(), |
|
|
|
|
|
atime = calendar:local_time()}). |
|
|
|
|
|
|
|
|
%% =================================================================== |
|
|
%% =================================================================== |
|
|
%% Internal functions |
|
|
%% Internal functions |
|
|
%% =================================================================== |
|
|
%% =================================================================== |
|
@ -201,28 +221,27 @@ delete_each_dir_win32([Dir | Rest]) -> |
|
|
delete_each_dir_win32(Rest). |
|
|
delete_each_dir_win32(Rest). |
|
|
|
|
|
|
|
|
xcopy_win32(Source,Dest)-> |
|
|
xcopy_win32(Source,Dest)-> |
|
|
{ok, R} = rebar_utils:sh( |
|
|
|
|
|
?FMT("xcopy \"~s\" \"~s\" /q /y /e 2> nul", |
|
|
|
|
|
|
|
|
%% "xcopy \"~s\" \"~s\" /q /y /e 2> nul", Chanegd to robocopy to |
|
|
|
|
|
%% handle long names. May have issues with older windows. |
|
|
|
|
|
Res = rebar_utils:sh( |
|
|
|
|
|
?FMT("robocopy \"~s\" \"~s\" /e /is 2> nul", |
|
|
[filename:nativename(Source), filename:nativename(Dest)]), |
|
|
[filename:nativename(Source), filename:nativename(Dest)]), |
|
|
[{use_stdout, false}, return_on_error]), |
|
|
[{use_stdout, false}, return_on_error]), |
|
|
case length(R) > 0 of |
|
|
|
|
|
%% when xcopy fails, stdout is empty and and error message is printed |
|
|
|
|
|
%% to stderr (which is redirected to nul) |
|
|
|
|
|
true -> ok; |
|
|
|
|
|
false -> |
|
|
|
|
|
{error, lists:flatten( |
|
|
|
|
|
io_lib:format("Failed to xcopy from ~s to ~s~n", |
|
|
|
|
|
[Source, Dest]))} |
|
|
|
|
|
|
|
|
case win32_robocopy_ok(Res) of |
|
|
|
|
|
true -> ok; |
|
|
|
|
|
false -> |
|
|
|
|
|
{error, lists:flatten( |
|
|
|
|
|
io_lib:format("Failed to copy ~s to ~s~n", |
|
|
|
|
|
[Source, Dest]))} |
|
|
end. |
|
|
end. |
|
|
|
|
|
|
|
|
cp_r_win32({true, SourceDir}, {true, DestDir}) -> |
|
|
cp_r_win32({true, SourceDir}, {true, DestDir}) -> |
|
|
%% from directory to directory |
|
|
%% from directory to directory |
|
|
SourceBase = filename:basename(SourceDir), |
|
|
|
|
|
ok = case file:make_dir(filename:join(DestDir, SourceBase)) of |
|
|
|
|
|
|
|
|
ok = case file:make_dir(DestDir) of |
|
|
{error, eexist} -> ok; |
|
|
{error, eexist} -> ok; |
|
|
Other -> Other |
|
|
Other -> Other |
|
|
end, |
|
|
end, |
|
|
ok = xcopy_win32(SourceDir, filename:join(DestDir, SourceBase)); |
|
|
|
|
|
|
|
|
ok = xcopy_win32(SourceDir, DestDir); |
|
|
cp_r_win32({false, Source} = S,{true, DestDir}) -> |
|
|
cp_r_win32({false, Source} = S,{true, DestDir}) -> |
|
|
%% from file to directory |
|
|
%% from file to directory |
|
|
cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))}); |
|
|
cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))}); |
|
|