diff options
author | Tristan Sloughter <[email protected]> | 2015-06-21 10:22:02 -0500 |
---|---|---|
committer | Tristan Sloughter <[email protected]> | 2015-06-21 10:22:02 -0500 |
commit | 4f38907d4967d672d3a2b13422cde2e13a42a604 (patch) | |
tree | fd6eb5fb93acd86c9dca01c9ffbdd029e4169b87 /src | |
parent | 87e87154fa52f815404e25d1ef59179253f9c5bb (diff) | |
parent | 04a945375a63542811d3af7bd14bc7d5c5b303d9 (diff) | |
download | relx-4f38907d4967d672d3a2b13422cde2e13a42a604.tar.gz relx-4f38907d4967d672d3a2b13422cde2e13a42a604.tar.bz2 relx-4f38907d4967d672d3a2b13422cde2e13a42a604.zip |
Merge pull request #349 from Taure/windows-fix
Fixing test for windows, changing symlink to symlink_or_copy
Diffstat (limited to 'src')
-rw-r--r-- | src/rlx_cmd_args.erl | 2 | ||||
-rw-r--r-- | src/rlx_prv_assembler.erl | 4 | ||||
-rw-r--r-- | src/rlx_util.erl | 85 |
3 files changed, 88 insertions, 3 deletions
diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl index 2039b43..309282e 100644 --- a/src/rlx_cmd_args.erl +++ b/src/rlx_cmd_args.erl @@ -318,6 +318,8 @@ convert_overrides([Override | Rest], Acc) case re:split(Override, ":") of [AppName, AppDir] -> convert_overrides(Rest, [{rlx_util:to_atom(AppName), AppDir} | Acc]); + [AppName, Drive, AppDir] -> + convert_overrides(Rest, [{rlx_util:to_atom(AppName), <<Drive/binary, ":", AppDir/binary>>} | Acc]); _ -> ?RLX_ERROR({failed_to_parse_override, Override}) end; diff --git a/src/rlx_prv_assembler.erl b/src/rlx_prv_assembler.erl index 79768d3..a3715e5 100644 --- a/src/rlx_prv_assembler.erl +++ b/src/rlx_prv_assembler.erl @@ -257,7 +257,7 @@ remove_symlink_or_directory(TargetDir) -> end. link_directory(AppDir, TargetDir) -> - case file:make_symlink(AppDir, TargetDir) of + case rlx_util:symlink_or_copy(AppDir, TargetDir) of {error, Reason} -> ?RLX_ERROR({unable_to_make_symlink, AppDir, TargetDir, Reason}); ok -> @@ -433,7 +433,7 @@ copy_or_symlink_config_file(State, ConfigPath, RelConfPath) -> ensure_not_exist(RelConfPath), case rlx_state:dev_mode(State) of true -> - ok = file:make_symlink(ConfigPath, RelConfPath); + ok = rlx_util:symlink_or_copy(ConfigPath, RelConfPath); _ -> ok = ec_file:copy(ConfigPath, RelConfPath) end. diff --git a/src/rlx_util.erl b/src/rlx_util.erl index 8a54ae6..db448e8 100644 --- a/src/rlx_util.erl +++ b/src/rlx_util.erl @@ -37,7 +37,8 @@ render/2, load_file/3, template_files/0, - escript_foldl/3]). + escript_foldl/3, + symlink_or_copy/2]). -define(ONE_LEVEL_INDENT, " "). %%============================================================================ @@ -212,6 +213,88 @@ escript_foldl(Fun, Acc, File) -> Error end. +symlink_or_copy(Source, Target) -> + case file:make_symlink(Source, Target) of + ok -> + ok; + {error, eexist} -> + ok; + {error, _} -> + case os:type() of + {win32, _} -> + win32_symlink(Source, Target); + _ -> + case filelib:is_dir(Target) of + true -> ok; + false -> + cp_r([Source], Target) + end + end + end. + + +win32_symlink(Source, Target) -> + os:cmd("cmd /c mklink /j " ++ Target ++ " " ++ Source), + ok. + +-spec cp_r(list(string()), file:filename()) -> 'ok'. +cp_r([], _Dest) -> + ok; +cp_r(Sources, Dest) -> + case os:type() of + {unix, _} -> + ok; + {win32, _} -> + lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources), + ok + end. + +xcopy_win32(Source,Dest)-> + %% "xcopy \"~s\" \"~s\" /q /y /e 2> nul", Chanegd to robocopy to + %% handle long names. May have issues with older windows. + os:cmd("robocopy " ++ Source ++ " " ++ Dest ++ " /e /is"), + ok. + +cp_r_win32({true, SourceDir}, {true, DestDir}) -> + %% from directory to directory + ok = case file:make_dir(DestDir) of + {error, eexist} -> ok; + Other -> Other + end, + ok = xcopy_win32(SourceDir, DestDir); +cp_r_win32({false, Source} = S,{true, DestDir}) -> + %% from file to directory + cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))}); +cp_r_win32({false, Source},{false, Dest}) -> + %% from file to file + {ok,_} = file:copy(Source, Dest), + ok; +cp_r_win32({true, SourceDir}, {false, DestDir}) -> + case filelib:is_regular(DestDir) of + true -> + %% From directory to file? This shouldn't happen + {error, lists:flatten( + io_lib:format("Cannot copy dir (~p) to file (~p)\n", + [SourceDir, DestDir]))}; + false -> + %% Specifying a target directory that doesn't currently exist. + %% So let's attempt to create this directory + case filelib:ensure_dir(filename:join(DestDir, "dummy")) of + ok -> + ok = xcopy_win32(SourceDir, DestDir); + {error, Reason} -> + {error, lists:flatten( + io_lib:format("Unable to create dir ~p: ~p\n", + [DestDir, Reason]))} + end + end; +cp_r_win32(Source,Dest) -> + Dst = {filelib:is_dir(Dest), Dest}, + lists:foreach(fun(Src) -> + ok = cp_r_win32({filelib:is_dir(Src), Src}, Dst) + end, filelib:wildcard(Source)), + ok. + %%%=================================================================== %%% Test Functions %%%=================================================================== |