From ea12b3eb5387145e9445137e4528a563e9004435 Mon Sep 17 00:00:00 2001 From: aamine Date: Mon, 27 Dec 2004 06:15:32 +0000 Subject: [PATCH] * 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@7661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ lib/fileutils.rb | 49 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b04070435..07c7451ba1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Dec 27 15:15:18 2004 Minero Aoki + + * 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. + Mon Dec 27 14:36:20 2004 NAKAMURA Usaku * process.c (NUM2RLIM, RLIM2NUM): Without SIZEOF_RLIM_T is not error. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 34efc4d85a..38478cea71 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 - File.unlink d - rescue SystemCallError - raise unless options[:force] - end - end + src_stat = fu_lstat(s) + dest_stat = fu_stat(d) begin - File.rename s, d - rescue SystemCallError - begin - copy_entry s, d, true - File.unlink s - rescue SystemCallError - raise unless options[:force] + if rename_cannot_overwrite_file? and dest_stat and not dest_stat.directory? + File.unlink d end + 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 + 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?