diff options
| author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-27 06:15:32 +0000 |
|---|---|---|
| committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-27 06:15:32 +0000 |
| commit | f5232710ad4de59c6513a4216a1e62bb872d1e32 (patch) | |
| tree | e5eb220ecd4e73f0f9811ed6a43c94d3cf2c2177 /lib/fileutils.rb | |
| parent | 6c67416006581cff2902c4ee6db572b789d58ca6 (diff) | |
| download | ruby-f5232710ad4de59c6513a4216a1e62bb872d1e32.tar.gz ruby-f5232710ad4de59c6513a4216a1e62bb872d1e32.tar.xz ruby-f5232710ad4de59c6513a4216a1e62bb872d1e32.zip | |
* lib/fileutils.rb (mv): should raise error when moving a directory to the (empty) directory. [ruby-talk:124368]
* lib/fileutils.rb (mv): wrongly did not overwrite file on Win32 platforms.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/fileutils.rb')
| -rw-r--r-- | lib/fileutils.rb | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 34efc4d85..38478cea7 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -75,6 +75,11 @@ require 'find' +unless defined?(Errno::EXDEV) + module Errno + class EXDEV < SystemCallError; end + end +end module FileUtils @@ -573,30 +578,44 @@ module FileUtils return if options[:noop] fu_each_src_dest(src, dest) do |s,d| - if rename_cannot_overwrite_file? and File.file?(d) - begin + src_stat = fu_lstat(s) + dest_stat = fu_stat(d) + begin + if rename_cannot_overwrite_file? and dest_stat and not dest_stat.directory? File.unlink d - rescue SystemCallError - raise unless options[:force] end - end - begin - File.rename s, d - rescue SystemCallError + if dest_stat and dest_stat.directory? + raise Errno::EISDIR, dest + end begin + File.rename s, d + rescue Errno::EXDEV copy_entry s, d, true - File.unlink s - rescue SystemCallError - raise unless options[:force] end + rescue SystemCallError + raise unless options[:force] end end end alias move mv + def fu_stat(path) + File.stat(path) + rescue SystemCallError + nil + end + private :fu_stat + + def fu_lstat(path) + File.lstat(path) + rescue SystemCallError + nil + end + private :fu_lstat + def rename_cannot_overwrite_file? #:nodoc: - /djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ !~ RUBY_PLATFORM + /djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM end private :rename_cannot_overwrite_file? |
