summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--lib/fileutils.rb33
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 <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] (2 items backportted from HEAD, rev 1.53-54)
+
Thu Apr 14 16:57:40 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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</\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