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> 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] * 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. * 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> Thu Apr 14 00:20:31 2005 Keiju Ishitsuka <keiju@ruby-lang.org>
* bin/irb lib/irb.rb lib/irb/...: IRB 0.9.5. * bin/irb lib/irb.rb lib/irb/...: IRB 0.9.5.

View file

@ -702,24 +702,30 @@ module FileUtils
alias rmtree rm_rf 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 first_time_p = true
begin begin
File.unlink fname File.unlink path
rescue Errno::ENOENT rescue Errno::ENOENT
raise unless force raise unless force
rescue rescue => err
if first_time_p if first_time_p
# try once more for Windows
first_time_p = false first_time_p = false
File.chmod 0777, fname begin
retry File.chmod 0777, path
retry
rescue SystemCallError
end
end end
raise unless force raise err unless force
end end
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| Dir.foreach(dir) do |file|
next if /\A\.\.?\z/ =~ file next if /\A\.\.?\z/ =~ file
path = "#{dir}/#{file.untaint}" path = "#{dir}/#{file.untaint}"
@ -731,10 +737,21 @@ module FileUtils
remove_file path, force remove_file path, force
end end
end end
first_time_p = true
begin begin
Dir.rmdir dir.sub(%r</\z>, '') Dir.rmdir dir.sub(%r</\z>, '')
rescue Errno::ENOENT rescue Errno::ENOENT
raise unless force 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
end end

View file

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