diff --git a/shelltests/powershell_release/rebar.config b/shelltests/powershell_release/rebar.config index aff3b4e7f..19ab18a10 100644 --- a/shelltests/powershell_release/rebar.config +++ b/shelltests/powershell_release/rebar.config @@ -8,3 +8,5 @@ {extended_start_script, true}, {start_script_type, "powershell"}] }. + +{profiles, [{dev, [{relx, [{dev_mode, true}]}]}]}. diff --git a/shelltests/wintest.ps1 b/shelltests/wintest.ps1 index bd72efaa8..8d51ca885 100644 --- a/shelltests/wintest.ps1 +++ b/shelltests/wintest.ps1 @@ -45,7 +45,12 @@ Pop-Location "" # Function to run rebar3 -function Rebar() { & $erlpath\bin\escript.exe "$rebar3_dir\rebar3" @args } +function Rebar() { + & $erlpath\bin\escript.exe "$rebar3_dir\rebar3" @args + if ($LASTEXITCODE -ne 0) { + Write-Error "rebar3 ${args} exited with status $LASTEXITCODE" + } +} # Our release source Set-Location ".\$release\" @@ -54,25 +59,45 @@ Set-Location ".\$release\" Rebar release "" +"*** Rebuild dev release (test for symlink issues)" +Rebar as dev release +Rebar as dev release +"" + # Go to release Set-Location "_build\default\rel\$release\bin" "*** Install service" & ".\$release.ps1" install +if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to install service" +} "" "*** Start service" & ".\$release.ps1" start +if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to start service" +} "" "*** Ping service" & ".\$release.ps1" ping +if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to ping service" +} "" "*** Stop service" & ".\$release.ps1" stop +if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to stop service" +} "" "*** Uninstall service" & ".\$release.ps1" uninstall -"" \ No newline at end of file +if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to uninstall service" +} +"" diff --git a/src/rlx_file_utils.erl b/src/rlx_file_utils.erl index 5f489de40..9f36b88c1 100644 --- a/src/rlx_file_utils.erl +++ b/src/rlx_file_utils.erl @@ -295,24 +295,31 @@ sub_files(From) -> {ok, SubFiles} = file:list_dir(From), [filename:join(From, SubFile) || SubFile <- SubFiles]. -%% @doc delete a file. Use the recursive option for directories. +%% @doc delete a file. Use the recursive option for whole directory trees. -spec remove(file:name(), [] | [recursive]) -> ok | {error, term()}. remove(Path, Options) -> case lists:member(recursive, Options) of - false -> file:delete(Path); + false -> remove(Path); true -> remove_recursive(Path, Options) end. -%% @doc delete a file. +%% @doc delete a file or directory, including symlinks and junctions -spec remove(file:name()) -> ok | {error, term()}. remove(Path) -> - remove(Path, []). + case is_symlink(Path) of + true -> remove_symlink(Path); + false -> + case is_dir(Path) of + true -> file:del_dir(Path); + false -> file:delete(Path) + end + end. -spec remove_recursive(file:name(), list()) -> ok | {error, term()}. remove_recursive(Path, Options) -> case is_dir(Path) of false -> - file:delete(Path); + remove(Path); true -> lists:foreach(fun(ChildPath) -> remove_recursive(ChildPath, Options) @@ -320,6 +327,20 @@ remove_recursive(Path, Options) -> file:del_dir(Path) end. +-spec remove_symlink(file:name()) -> ok | {error, term()}. +remove_symlink(Path) -> + case os:type() of + {win32, _} -> + % On windows we remove symlinks and junctions differently if they refer to directories. + case filelib:is_dir(Path) of + true -> file:del_dir(Path); + false -> file:delete(Path) + end; + _ -> + % On other systems we use can use file:delete() in all cases. + file:delete(Path) + end. + %% returns the path for printing to logs. if get_cwd succeeds it %% attempts to return the relative path. It falls back on juts %% returning the original path.