aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Breddin <[email protected]>2019-04-16 16:17:10 +0200
committerTino Breddin <[email protected]>2019-04-16 16:30:04 +0200
commit476b439de0077b6f7a60622d2498b85e6f52698a (patch)
tree0ff017728bcb312551e8b9d6c784886fa366cfab
parent07943b1b41e8d1ffdf8b9f770e623212581b12cd (diff)
downloadrelx-476b439de0077b6f7a60622d2498b85e6f52698a.tar.gz
relx-476b439de0077b6f7a60622d2498b85e6f52698a.tar.bz2
relx-476b439de0077b6f7a60622d2498b85e6f52698a.zip
Use recursive copy as last fallback on all platforms
-rw-r--r--src/rlx_util.erl31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/rlx_util.erl b/src/rlx_util.erl
index 1893353..5d3744d 100644
--- a/src/rlx_util.erl
+++ b/src/rlx_util.erl
@@ -235,26 +235,28 @@ symlink_or_copy(Source, Target) ->
ok;
{error, eexist} ->
{error, eexist};
- {error, eperm} = Error ->
- % We get eperm on Windows if we do not have
- % SeCreateSymbolicLinkPrivilege
- % Try the next alternative
- case os:type() of
- {win32, _} ->
+ {error, Err} ->
+ case {os:type(), Err} of
+ {{win32, _}, eperm} ->
+ % We get eperm on Windows if we do not have
+ % SeCreateSymbolicLinkPrivilege
+ % Try the next alternative
win32_make_junction_or_copy(Source, Target);
_ ->
- Error
- end;
- {error, _} = Error ->
- Error
+ % On other systems we try to copy next
+ cp_r(Source, Target)
+ end
end.
+cp_r(Source, Target) ->
+ ec_file:copy(Source, Target, [{recursive, true}, {fileinfo, [mode, time, owner, group]}]).
+
win32_make_junction_or_copy(Source, Target) ->
case filelib:is_dir(Source) of
true ->
win32_make_junction(Source, Target);
_ ->
- ec_file:copy(Source, Target)
+ cp_r(Source, Target)
end.
win32_make_junction(Source, Target) ->
@@ -272,8 +274,9 @@ win32_make_junction(Source, Target) ->
{error, Reason} ->
{error, {readlink, Reason}}
end;
- {ok, #file_info{type = Type}} ->
- {error, {mklink_cannot_replace_existing, Type, Target}};
+ {ok, #file_info{type = _Type}} ->
+ % Directory already exists, so we overwrite the copy
+ cp_r(Source, Target);
Error ->
Error
end.
@@ -289,7 +292,7 @@ win32_make_junction_cmd(Source, Target) ->
% When mklink fails it prints the error message to stderr which
% is not picked up by os:cmd() hence this case switch is for
% an empty message
- {error, make_junction_failed}
+ cp_r(Source, Target)
end.
%% @doc Returns the color intensity, we first check the application envorinment