summaryrefslogtreecommitdiff
path: root/lib/fileutils.rb
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2022-07-26 21:31:27 +0900
committergit <svn-admin@ruby-lang.org>2022-08-23 16:52:41 +0900
commit983115cf3c8f75b1afbe3274f02c1529e1ce3a81 (patch)
tree88a408b75d1f0027e89b0f5f74bd0cd72e20df67 /lib/fileutils.rb
parent96562a517d3373466ec306b5f821a41f4758d2a6 (diff)
downloadruby-983115cf3c8f75b1afbe3274f02c1529e1ce3a81.tar.gz
[ruby/fileutils] FileUtils.rm* methods swallows only Errno::ENOENT when force is true
... instead of any StandardError. To behave like the standard `rm` command, it should only ignore exceptions about not existing files, not every exception. This should make debugging some errors easier, because the expectation is that `rm -rf` will succeed if and only if, all given files (previously existent or not) are removed. However, due to this exception swallowing, this is not always the case. From the `rm` man page > COMPATIBILITY > > The rm utility differs from historical implementations in that the -f > option only masks attempts to remove non-existent files instead of > masking a large variety of errors. https://github.com/ruby/fileutils/commit/fa65d676ec Co-Authored-By: David Rodríguez <deivid.rodriguez@riseup.net>
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r--lib/fileutils.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index 4ba7d18a5d..74bb904e28 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -1165,7 +1165,7 @@ module FileUtils
#
# Keyword arguments:
#
- # - <tt>force: true</tt> - ignores raised exceptions of StandardError
+ # - <tt>force: true</tt> - ignores raised exceptions of Errno::ENOENT
# and its descendants.
# - <tt>noop: true</tt> - does not remove files; returns +nil+.
# - <tt>verbose: true</tt> - prints an equivalent command:
@@ -1248,7 +1248,7 @@ module FileUtils
#
# Keyword arguments:
#
- # - <tt>force: true</tt> - ignores raised exceptions of StandardError
+ # - <tt>force: true</tt> - ignores raised exceptions of Errno::ENOENT
# and its descendants.
# - <tt>noop: true</tt> - does not remove entries; returns +nil+.
# - <tt>secure: true</tt> - removes +src+ securely;
@@ -1315,7 +1315,7 @@ module FileUtils
# see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
#
# Optional argument +force+ specifies whether to ignore
- # raised exceptions of StandardError and its descendants.
+ # raised exceptions of Errno::ENOENT and its descendants.
#
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
#
@@ -1384,10 +1384,12 @@ module FileUtils
ent.remove
rescue
raise unless force
+ raise unless Errno::ENOENT === $!
end
end
rescue
raise unless force
+ raise unless Errno::ENOENT === $!
end
module_function :remove_entry_secure
@@ -1413,7 +1415,7 @@ module FileUtils
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
#
# Optional argument +force+ specifies whether to ignore
- # raised exceptions of StandardError and its descendants.
+ # raised exceptions of Errno::ENOENT and its descendants.
#
# Related: FileUtils.remove_entry_secure.
#
@@ -1423,10 +1425,12 @@ module FileUtils
ent.remove
rescue
raise unless force
+ raise unless Errno::ENOENT === $!
end
end
rescue
raise unless force
+ raise unless Errno::ENOENT === $!
end
module_function :remove_entry
@@ -1437,7 +1441,7 @@ module FileUtils
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
#
# Optional argument +force+ specifies whether to ignore
- # raised exceptions of StandardError and its descendants.
+ # raised exceptions of Errno::ENOENT and its descendants.
#
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
#
@@ -1445,6 +1449,7 @@ module FileUtils
Entry_.new(path).remove_file
rescue
raise unless force
+ raise unless Errno::ENOENT === $!
end
module_function :remove_file
@@ -1456,7 +1461,7 @@ module FileUtils
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
#
# Optional argument +force+ specifies whether to ignore
- # raised exceptions of StandardError and its descendants.
+ # raised exceptions of Errno::ENOENT and its descendants.
#
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
#