Ensure symlink_or_copy can override previous symlinks
This commit is contained in:
@@ -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, _ } ->
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user