From f42db5e7859c6e7986250e9fd069fb87d597dbdb Mon Sep 17 00:00:00 2001 From: aamine Date: Thu, 14 Apr 2005 10:19:11 +0000 Subject: * lib/fileutils.rb (remove_file): ignore exceptions caused by chmod. * lib/fileutils.rb (remove_dir): try to get rights to rmdir. [ruby-Bugs:1502] (2 items backportted from HEAD, rev 1.53-54) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ lib/fileutils.rb | 33 +++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2516b2c447..4896600020 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Apr 14 19:18:30 2005 Minero Aoki + + * lib/fileutils.rb (remove_file): ignore exceptions caused by + chmod. + + * lib/fileutils.rb (remove_dir): try to get rights to rmdir. + [ruby-Bugs:1502] (2 items backportted from HEAD, rev 1.53-54) + Thu Apr 14 16:57:40 2005 Nobuyoshi Nakada * bcc32/Makefile.sub: failed to remove debug information files. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 287319c4b3..931eabff8b 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -701,24 +701,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 + 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}" @@ -730,10 +736,21 @@ module FileUtils remove_file path, force end end + first_time_p = true begin Dir.rmdir dir.sub(%r, '') 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 -- cgit v1.2.3