aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/rcl_prv_assembler.erl48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/rcl_prv_assembler.erl b/src/rcl_prv_assembler.erl
index b8766df..a721b12 100644
--- a/src/rcl_prv_assembler.erl
+++ b/src/rcl_prv_assembler.erl
@@ -127,29 +127,28 @@ copy_app(LibDir, App) ->
AppVsn = rcl_app_info:vsn_as_string(App),
AppDir = rcl_app_info:dir(App),
TargetDir = filename:join([LibDir, AppName ++ "-" ++ AppVsn]),
+ remove_symlink_or_directory(TargetDir),
case rcl_app_info:link(App) of
true ->
link_directory(AppDir, TargetDir);
false ->
- ok = rcl_util:mkdir_p(TargetDir),
- ec_plists:map(fun(SubDir) ->
- copy_dir(AppDir, TargetDir, SubDir)
- end, ["ebin",
- "include",
- "priv",
- "src",
- "c_src",
- "README",
- "LICENSE"])
+ copy_directory(AppDir, TargetDir)
end.
-link_directory(AppDir, TargetDir) ->
- case ec_file:exists(TargetDir) of
+remove_symlink_or_directory(TargetDir) ->
+ case ec_file:is_symlink(TargetDir) of
true ->
ec_file:remove(TargetDir);
false ->
- ok
- end,
+ case filelib:is_dir(TargetDir) of
+ true ->
+ ok = ec_file:remove(TargetDir, [recursive]);
+ false ->
+ ok
+ end
+ end.
+
+link_directory(AppDir, TargetDir) ->
case file:make_symlink(AppDir, TargetDir) of
{error, Reason} ->
?RCL_ERROR({unable_to_make_symlink, AppDir, TargetDir, Reason});
@@ -157,21 +156,26 @@ link_directory(AppDir, TargetDir) ->
ok
end.
+copy_directory(AppDir, TargetDir) ->
+ ec_plists:map(fun(SubDir) ->
+ copy_dir(AppDir, TargetDir, SubDir)
+ end, ["ebin",
+ "include",
+ "priv",
+ "src",
+ "c_src",
+ "README",
+ "LICENSE"]).
+
copy_dir(AppDir, TargetDir, SubDir) ->
SubSource = filename:join(AppDir, SubDir),
SubTarget = filename:join(TargetDir, SubDir),
case filelib:is_dir(SubSource) of
true ->
- case filelib:is_dir(SubTarget) of
- true ->
- ok = ec_file:remove(SubTarget, [recursive]);
- false ->
- ok
- end,
- ok = filelib:ensure_dir(SubTarget),
+ ok = rcl_util:mkdir_p(SubTarget),
case ec_file:copy(SubSource, SubTarget, [recursive]) of
{error, E} ->
- ?RCL_ERROR({ec_file_error, AppDir, TargetDir, E});
+ ?RCL_ERROR({ec_file_error, AppDir, SubTarget, E});
ok ->
ok
end;