mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improve same directory detection in FileUtils
Closes: https://github.com/ruby/ruby/pull/1425
This commit is contained in:
parent
96cec6b277
commit
4f1a00a746
2 changed files with 15 additions and 2 deletions
|
@ -1546,10 +1546,13 @@ module FileUtils
|
|||
else
|
||||
DIRECTORY_TERM = "(?=/|\\z)"
|
||||
end
|
||||
SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : ""
|
||||
|
||||
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 # 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/c', 'tmp/cpr_dest/c'
|
||||
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_dest'
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue