summaryrefslogtreecommitdiff
path: root/lib/fileutils.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r--lib/fileutils.rb45
1 files changed, 32 insertions, 13 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index dbf993d2e9..5548c4cd1b 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?