From f776bab39c5803c7fb937abf6e7e72c98eecd3b2 Mon Sep 17 00:00:00 2001 From: aamine Date: Mon, 27 Dec 2004 06:22:14 +0000 Subject: * 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 --- lib/fileutils.rb | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'lib') 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 @@ # :verbose 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? -- cgit