diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-27 06:22:14 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-27 06:22:14 +0000 |
commit | f776bab39c5803c7fb937abf6e7e72c98eecd3b2 (patch) | |
tree | d713ca572f369b13194e83d3cafd21382db16e29 | |
parent | eebc1e93b8f387b2234048feb68f47c36ad98ce8 (diff) | |
download | ruby-f776bab39c5803c7fb937abf6e7e72c98eecd3b2.tar.gz ruby-f776bab39c5803c7fb937abf6e7e72c98eecd3b2.tar.xz ruby-f776bab39c5803c7fb937abf6e7e72c98eecd3b2.zip |
* lib/fileutils.rb (mv): should raise error when moving a directory to the (empty) directory. [ruby-talk:124368] (backport from HEAD 1.48)
* lib/fileutils.rb (mv): wrongly did not overwrite file on Win32 platforms. (backport from HEAD 1.48)
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/fileutils.rb | 45 |
2 files changed, 41 insertions, 13 deletions
@@ -1,3 +1,12 @@ +Mon Dec 27 15:21:07 2004 Minero Aoki <aamine@loveruby.net> + + * lib/fileutils.rb (mv): should raise error when moving a + directory to the (empty) directory. [ruby-talk:124368] + (backport from HEAD 1.48) + + * lib/fileutils.rb (mv): wrongly did not overwrite file on Win32 + platforms. (backport from HEAD 1.48) + Sat Dec 25 11:11:48 2004 Yukihiro Matsumoto <matz@ruby-lang.org> * stable version 1.8.2 released. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index dbf993d2e..5548c4cd1 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -73,6 +73,12 @@ # <tt>:verbose</tt> flags to methods in FileUtils. # +unless defined?(Errno::EXDEV) + module Errno + class EXDEV < SystemCallError; end + end +end + module FileUtils # All methods are module_function. @@ -107,7 +113,6 @@ module FileUtils alias chdir cd - # # Options: (none) # @@ -570,30 +575,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? |