Ensure symlink_or_copy can override previous symlinks

This commit is contained in:
José Valim
2013-11-15 08:42:07 +01:00
parent ff679125e6
commit fb5c963f17
2 changed files with 14 additions and 1 deletions
+5 -1
View File
@@ -322,7 +322,11 @@ defmodule Mix.Utils do
if File.exists?(source) do
source_list = String.to_char_list!(source)
case :file.read_link(target) do
{ :ok, ^source_list } -> :ok
{ :ok, ^source_list } ->
:ok
{ :ok, _ } ->
File.rm!(target)
do_symlink_or_copy(source, target)
{ :error, :enoent } ->
do_symlink_or_copy(source, target)
{ :error, _ } ->
+9
View File
@@ -93,4 +93,13 @@ defmodule Mix.UtilsTest do
assert :file.read_link("_build/archive/ebin") == { :ok, Path.expand('ebin') }
end
end
test :symlink_or_copy_erases_wrong_symblinks do
in_fixture "archive", fn ->
File.mkdir_p!("_build/archive")
Mix.Utils.symlink_or_copy(Path.expand("priv"), "_build/archive/ebin")
Mix.Utils.symlink_or_copy(Path.expand("ebin"), "_build/archive/ebin")
assert :file.read_link("_build/archive/ebin") == { :ok, Path.expand('ebin') }
end
end
end