* 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> Mon Dec 27 14:36:20 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* process.c (NUM2RLIM, RLIM2NUM): Without SIZEOF_RLIM_T is not error. * process.c (NUM2RLIM, RLIM2NUM): Without SIZEOF_RLIM_T is not error.

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

@ -75,6 +75,11 @@
require 'find' require 'find'
unless defined?(Errno::EXDEV)
module Errno
class EXDEV < SystemCallError; end
end
end
module FileUtils module FileUtils
@ -573,30 +578,44 @@ module FileUtils
return if options[:noop] return if options[:noop]
fu_each_src_dest(src, dest) do |s,d| fu_each_src_dest(src, dest) do |s,d|
if rename_cannot_overwrite_file? and File.file?(d) src_stat = fu_lstat(s)
begin dest_stat = fu_stat(d)
File.unlink d
rescue SystemCallError
raise unless options[:force]
end
end
begin begin
File.rename s, d if rename_cannot_overwrite_file? and dest_stat and not dest_stat.directory?
rescue SystemCallError File.unlink d
begin
copy_entry s, d, true
File.unlink s
rescue SystemCallError
raise unless options[:force]
end 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 end
end end
alias move mv 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: 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 end
private :rename_cannot_overwrite_file? private :rename_cannot_overwrite_file?