summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/fileutils.rb7
-rw-r--r--test/fileutils/test_fileutils.rb10
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index ff667fb1b0..cfc6ef1ec8 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -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_
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index c81f5b40dc..18a4bed39e 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -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'