diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-06 13:59:37 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-09-06 13:59:37 +0000 |
commit | 9a46ab6b6264ea428e6424b6d6b898a0bbf73af4 (patch) | |
tree | f3e77a4ecdfe00ee86d793254fb9fddc501cec42 | |
parent | 205d12524c163416207bc8d0be26b873383fff21 (diff) | |
download | ruby-9a46ab6b6264ea428e6424b6d6b898a0bbf73af4.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/fileutils.rb | 11 |
2 files changed, 16 insertions, 4 deletions
@@ -1,3 +1,12 @@ +Thu Sep 6 22:57:01 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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 <matz@ruby-lang.org> * 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 |