Compare commits

...
2 Commits
Author SHA1 Message Date
Dmitry Kakurin 762989b39f Fix Path.absname/1 to correctly handle UNC paths on Windows (#9689) 2020-01-06 21:44:27 +01:00
Lasse Skindstad Ebert 1767df4747 Fix release tar when include_erts is false (#9570)
Now excludes files that does not exist on the file system. This could
happen e.g. if the release is built with `include_erts: false`.

Otherwise building the tar would fail with `:enoent`.
2019-11-22 11:20:54 +01:00
4 changed files with 47 additions and 3 deletions
+7 -2
View File
@@ -95,6 +95,8 @@ defmodule Path do
absname(absname_join(name), cwd)
end
@slash [?/, ?\\]
# Joins a list
defp absname_join([name1, name2 | rest]), do: absname_join([absname_join(name1, name2) | rest])
@@ -110,6 +112,11 @@ defmodule Path do
do_absname_join(rest, relativename, [?:, uc_letter + ?a - ?A], :win32)
end
defp do_absname_join(<<c1, c2, rest::binary>>, relativename, [], :win32)
when c1 in @slash and c2 in @slash do
do_absname_join(rest, relativename, '//', :win32)
end
defp do_absname_join(<<?\\, rest::binary>>, relativename, result, :win32),
do: do_absname_join(<<?/, rest::binary>>, relativename, result, :win32)
@@ -254,8 +261,6 @@ defmodule Path do
defp unix_pathtype([list | rest]) when is_list(list), do: unix_pathtype(list ++ rest)
defp unix_pathtype(relative), do: {:relative, relative}
@slash [?/, ?\\]
defp win32_pathtype([list | rest]) when is_list(list), do: win32_pathtype(list ++ rest)
defp win32_pathtype([char, list | rest]) when is_list(list),
+12
View File
@@ -39,6 +39,13 @@ defmodule PathTest do
describe "Windows" do
@describetag :windows
test "absname/1" do
assert Path.absname("//host/path") == "//host/path"
assert Path.absname("\\\\host\\path") == "//host/path"
assert Path.absname("\\/host\\path") == "//host/path"
assert Path.absname("/\\host\\path") == "//host/path"
end
test "relative/1" do
assert Path.relative("C:/usr/local/bin") == "usr/local/bin"
assert Path.relative("C:\\usr\\local\\bin") == "usr\\local\\bin"
@@ -67,6 +74,11 @@ defmodule PathTest do
assert Path.type("/usr/local/bin") == :volumerelative
assert Path.type('usr/local/bin') == :relative
assert Path.type("../usr/local/bin") == :relative
assert Path.type("//host/path") == :absolute
assert Path.type("\\\\host\\path") == :absolute
assert Path.type("/\\host\\path") == :absolute
assert Path.type("\\/host\\path") == :absolute
end
test "split/1" do
+3 -1
View File
@@ -1033,7 +1033,9 @@ defmodule Mix.Tasks.Release do
lib_dirs ++ release_files
files =
Enum.map(dirs, &{String.to_charlist(&1), String.to_charlist(Path.join(release.path, &1))})
dirs
|> Enum.filter(&File.exists?(Path.join(release.path, &1)))
|> Enum.map(&{String.to_charlist(&1), String.to_charlist(Path.join(release.path, &1))})
File.rm(out_path)
:ok = :erl_tar.create(String.to_charlist(out_path), files, [:dereference, :compressed])
+25
View File
@@ -67,6 +67,8 @@ defmodule Mix.Tasks.ReleaseTest do
assert "releases/0.1.0/vm.args" in files
assert "releases/COOKIE" in files
assert "releases/start_erl.data" in files
assert Enum.any?(files, &(&1 =~ "erts"))
assert Enum.any?(files, &(&1 =~ "stdlib"))
for dir <- files_with_versions -- ["ignored_app-0.1.0"] do
[name | _] = String.split(dir, "-")
@@ -79,6 +81,29 @@ defmodule Mix.Tasks.ReleaseTest do
end)
end
test "tar without ERTS" do
in_fixture("release_test", fn ->
config = [releases: [demo: [include_erts: false, steps: [:assemble, :tar]]]]
Mix.Project.in_project(:release_test, ".", config, fn _ ->
root = Path.absname("_build/#{Mix.env()}/rel/demo")
Mix.Task.run("release")
tar_path = Path.expand(Path.join([root, "..", "..", "demo-0.1.0.tar.gz"]))
message = "* building #{tar_path}"
assert_received {:mix_shell, :info, [^message]}
assert File.exists?(tar_path)
{:ok, files} = String.to_charlist(tar_path) |> :erl_tar.table([:compressed])
files = Enum.map(files, &to_string/1)
assert "bin/demo" in files
refute Enum.any?(files, &(&1 =~ "erts"))
refute Enum.any?(files, &(&1 =~ "stdlib"))
end)
end)
end
test "steps" do
in_fixture("release_test", fn ->
last_step = fn release ->