From 9a46ab6b6264ea428e6424b6d6b898a0bbf73af4 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 6 Sep 2007 13:59:37 +0000 Subject: * lib/fileutils.rb (FileUtils::Entry_::copy): prevent self copy of directories. * lib/fileutils.rb (FileUtils::fu_each_src_dest0): use try_convert. * lib/fileutils.rb (FileUtils::fu_update_option): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ lib/fileutils.rb | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce860ae6c4..558808353b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Thu Sep 6 22:57:01 2007 Yukihiro Matsumoto + + * lib/fileutils.rb (FileUtils::Entry_::copy): prevent self copy of + directories. + + * lib/fileutils.rb (FileUtils::fu_each_src_dest0): use try_convert. + + * lib/fileutils.rb (FileUtils::fu_update_option): ditto. + Thu Sep 6 21:36:33 2007 Yukihiro Matsumoto * include/ruby/oniguruma.h (OnigEncodingTypeST): add end parameter diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 35bfd4b76f..6152c3d306 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1224,6 +1224,9 @@ module FileUtils when file? copy_file dest when directory? + if !File.exist?(dest) and /^#{Regexp.quote(path)}/ =~ File.dirname(dest) + raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest] + end begin Dir.mkdir dest rescue @@ -1392,8 +1395,8 @@ module FileUtils private_module_function :fu_each_src_dest def fu_each_src_dest0(src, dest) #:nodoc: - if src.is_a?(Array) - src.each do |s| + if tmp = Array.try_convert(src) + tmp.each do |s| s = File.path(s) yield s, File.join(dest, File.basename(s)) end @@ -1436,8 +1439,8 @@ module FileUtils private_module_function :fu_check_options def fu_update_option(args, new) #:nodoc: - if args.last.is_a?(Hash) - args[-1] = args.last.dup.update(new) + if tmp = Hash.try_convert(args.last) + args[-1] = tmp.dup.update(new) else args.push new end -- cgit v1.2.3