* 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
This commit is contained in:
aamine 2004-12-27 06:15:32 +00:00
Родитель 46df1a4c80
Коммит ea12b3eb53
2 изменённых файлов: 42 добавлений и 15 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Mon Dec 27 15:15:18 2004 Minero Aoki <aamine@loveruby.net>
* 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 <usa@ruby-lang.org>
* process.c (NUM2RLIM, RLIM2NUM): Without SIZEOF_RLIM_T is not error.

Просмотреть файл

@ -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?