aboutsummaryrefslogtreecommitdiffstats
path: root/src/rcl_prv_assembler.erl
diff options
context:
space:
mode:
authorEric <[email protected]>2012-12-21 10:42:57 -0500
committerEric <[email protected]>2012-12-21 10:42:57 -0500
commit3cbd64cce8ce1df48f1982819297bb3ba63c0191 (patch)
treee241f33cfd64d9a0adfc8577bf56d432b9d6c72d /src/rcl_prv_assembler.erl
parent16368e6531d6bdcd6a2f6a92bd18a20c131766f0 (diff)
downloadrelx-3cbd64cce8ce1df48f1982819297bb3ba63c0191.tar.gz
relx-3cbd64cce8ce1df48f1982819297bb3ba63c0191.tar.bz2
relx-3cbd64cce8ce1df48f1982819297bb3ba63c0191.zip
refactor rcl_prv_assembler for symplicity and reliability
Diffstat (limited to 'src/rcl_prv_assembler.erl')
-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;