Improve same directory detection in FileUtils
Closes: https://github.com/ruby/ruby/pull/1425
This commit is contained in:
parent
96cec6b277
commit
4f1a00a746
@ -1546,10 +1546,13 @@ module FileUtils
|
|||||||
else
|
else
|
||||||
DIRECTORY_TERM = "(?=/|\\z)"
|
DIRECTORY_TERM = "(?=/|\\z)"
|
||||||
end
|
end
|
||||||
SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : ""
|
|
||||||
|
|
||||||
def descendant_directory?(descendant, ascendant)
|
def descendant_directory?(descendant, ascendant)
|
||||||
/\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant)
|
if File::FNM_SYSCASE.nonzero?
|
||||||
|
File.expand_path(File.dirname(descendant)).casecmp(File.expand_path(ascendant)) == 0
|
||||||
|
else
|
||||||
|
File.expand_path(File.dirname(descendant)) == File.expand_path(ascendant)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end # class Entry_
|
end # class Entry_
|
||||||
|
|
||||||
|
@ -381,6 +381,16 @@ class TestFileUtils < Test::Unit::TestCase
|
|||||||
assert_same_file 'tmp/cpr_src/b', 'tmp/cpr_dest/b'
|
assert_same_file 'tmp/cpr_src/b', 'tmp/cpr_dest/b'
|
||||||
assert_same_file 'tmp/cpr_src/c', 'tmp/cpr_dest/c'
|
assert_same_file 'tmp/cpr_src/c', 'tmp/cpr_dest/c'
|
||||||
assert_directory 'tmp/cpr_dest/d'
|
assert_directory 'tmp/cpr_dest/d'
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
cp_r 'tmp/cpr_src', './tmp/cpr_src'
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
cp_r './tmp/cpr_src', 'tmp/cpr_src'
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
cp_r './tmp/cpr_src', File.expand_path('tmp/cpr_src')
|
||||||
|
end
|
||||||
|
|
||||||
my_rm_rf 'tmp/cpr_src'
|
my_rm_rf 'tmp/cpr_src'
|
||||||
my_rm_rf 'tmp/cpr_dest'
|
my_rm_rf 'tmp/cpr_dest'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user