1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/fileutils.rb (remove_file): ignore exceptions caused by chmod.

* lib/fileutils.rb (remove_dir): try to get rights to rmdir. [ruby-Bugs:1502]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2005-04-14 10:00:52 +00:00
parent ce7c263fb6
commit af759b81a1
3 changed files with 62 additions and 21 deletions

View file

@ -1,3 +1,11 @@
Thu Apr 14 18:59:43 2005 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (remove_file): ignore exceptions caused by
chmod.
* lib/fileutils.rb (remove_dir): try to get rights to rmdir.
[ruby-Bugs:1502]
Thu Apr 14 18:51:02 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
* lib/irb/ruby-lex.rb, lib/irb/slex.rb: bug fix of [ruby-Bugs-1745]
@ -16,8 +24,7 @@ Thu Apr 14 05:35:45 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
* doc/irb/irb.rd.ja: a lost of release IRB 0.9.5.
* lib/irb/slex.rb: bug fix by [ruby-core :04707].
* lib/irb/slex.rb: bug fix by [ruby-core:04707].
Thu Apr 14 00:20:31 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
* bin/irb lib/irb.rb lib/irb/...: IRB 0.9.5.

View file

@ -702,24 +702,30 @@ module FileUtils
alias rmtree rm_rf
def remove_file(fname, force = false) #:nodoc:
# Removes a file +path+.
# This method ignores StandardError if +force+ is true.
def remove_file(path, force = false)
first_time_p = true
begin
File.unlink fname
File.unlink path
rescue Errno::ENOENT
raise unless force
rescue
rescue => err
if first_time_p
# try once more for Windows
first_time_p = false
File.chmod 0777, fname
retry
begin
File.chmod 0777, path
retry
rescue SystemCallError
end
end
raise unless force
raise err unless force
end
end
def remove_dir(dir, force = false) #:nodoc:
# Removes a directory +dir+ and its contents recursively.
# This method ignores StandardError if +force+ is true.
def remove_dir(dir, force = false)
Dir.foreach(dir) do |file|
next if /\A\.\.?\z/ =~ file
path = "#{dir}/#{file.untaint}"
@ -731,10 +737,21 @@ module FileUtils
remove_file path, force
end
end
first_time_p = true
begin
Dir.rmdir dir.sub(%r</\z>, '')
rescue Errno::ENOENT
raise unless force
rescue => err
if first_time_p
first_time_p = false
begin
File.chmod 0777, dir
retry
rescue SystemCallError
end
end
raise err unless force
end
end

View file

@ -89,7 +89,6 @@ class TestFileUtils
my_rm_rf 'data'; mymkdir 'data'
my_rm_rf 'tmp'; mymkdir 'tmp'
prepare_data_file
prepare_time_data
end
def teardown
@ -146,9 +145,9 @@ class TestFileUtils
File.utime t-4, t-4, 'data/newer'
end
def each_sample_file
TARGETS.each do |srcpath|
yield srcpath, "tmp/#{File.basename(srcpath)}"
def each_srcdest
TARGETS.each do |path|
yield path, "tmp/#{File.basename(path)}"
end
end
@ -191,7 +190,7 @@ end
end
def test_cp
each_sample_file do |srcpath, destpath|
each_srcdest do |srcpath, destpath|
cp srcpath, destpath
assert_same_file srcpath, destpath
@ -753,7 +752,7 @@ end
end
def test_copy_entry
each_sample_file do |srcpath, destpath|
each_srcdest do |srcpath, destpath|
copy_entry srcpath, destpath
assert_same_file srcpath, destpath
assert_equal File.stat(srcpath).ftype, File.stat(destpath).ftype
@ -766,7 +765,7 @@ end
end
def test_copy_file
each_sample_file do |srcpath, destpath|
each_srcdest do |srcpath, destpath|
copy_file srcpath, destpath
assert_same_file srcpath, destpath
end
@ -774,7 +773,7 @@ end
def test_copy_stream
# IO
each_sample_file do |srcpath, destpath|
each_srcdest do |srcpath, destpath|
File.open(srcpath) {|src|
File.open(destpath, 'w') {|dest|
copy_stream src, dest
@ -786,7 +785,7 @@ end
# duck typing test [ruby-dev:25369]
rm_rf 'tmp'
Dir.mkdir 'tmp'
each_sample_file do |srcpath, destpath|
each_srcdest do |srcpath, destpath|
File.open(srcpath) {|src|
File.open(destpath, 'w') {|dest|
copy_stream Stream.new(src), Stream.new(dest)
@ -797,11 +796,28 @@ end
end
def test_remove_file
# FIXME
File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
remove_file 'data/tmp'
assert_file_not_exist 'data/tmp'
if have_file_perm?
File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
File.chmod 0, 'data/tmp'
remove_file 'data/tmp'
assert_file_not_exist 'data/tmp'
end
end
def test_remove_dir
# FIXME
Dir.mkdir 'data/tmpdir'
File.open('data/tmpdir/a', 'w') {|f| f.puts 'dummy' }
remove_dir 'data/tmpdir'
assert_file_not_exist 'data/tmpdir'
if have_file_perm?
Dir.mkdir 'data/tmpdir'
File.chmod 0555, 'data/tmpdir'
remove_dir 'data/tmpdir'
assert_file_not_exist 'data/tmpdir'
end
end
def test_compare_file
@ -827,6 +843,7 @@ end
end
def test_uptodate?
prepare_time_data
Dir.chdir('data') {
assert( uptodate?('newest', %w(old newer notexist)) )
assert( ! uptodate?('newer', %w(old newest notexist)) )