summaryrefslogtreecommitdiff
path: root/lib/fileutils.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-27 06:15:32 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-27 06:15:32 +0000
commitea12b3eb5387145e9445137e4528a563e9004435 (patch)
treee5eb220ecd4e73f0f9811ed6a43c94d3cf2c2177 /lib/fileutils.rb
parent46df1a4c8019d0b54756237cc099acb8d5b94261 (diff)
* 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
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r--lib/fileutils.rb43
1 files changed, 31 insertions, 12 deletions
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
+ 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?