diff options
author | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-04-14 10:19:11 +0000 |
---|---|---|
committer | aamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-04-14 10:19:11 +0000 |
commit | f42db5e7859c6e7986250e9fd069fb87d597dbdb (patch) | |
tree | 21b1fd7e0d967c50af3a80ab858df488ed2a771d /lib/fileutils.rb | |
parent | 4563088af8bff1f1f2aab29e7f4b4e2a02b30777 (diff) |
* 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
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r-- | lib/fileutils.rb | 33 |
1 files changed, 25 insertions, 8 deletions
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 |