Skip to content

Commit 42983c2

Browse files
committed
Revert "FileUtils.rm* methods swallows only Errno::ENOENT when force is true"
This reverts commit fa65d67. This caused some incompatibility problems in real-world cases. https://bugs.ruby-lang.org/issues/18784#change-98927 https://bugs.ruby-lang.org/issues/18784#change-98967
1 parent edd8d3b commit 42983c2

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

lib/fileutils.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
11651165
#
11661166
# Keyword arguments:
11671167
#
1168-
# - <tt>force: true</tt> - ignores raised exceptions of Errno::ENOENT
1168+
# - <tt>force: true</tt> - ignores raised exceptions of StandardError
11691169
# and its descendants.
11701170
# - <tt>noop: true</tt> - does not remove files; returns +nil+.
11711171
# - <tt>verbose: true</tt> - prints an equivalent command:
@@ -1248,7 +1248,7 @@ def rm_f(list, noop: nil, verbose: nil)
12481248
#
12491249
# Keyword arguments:
12501250
#
1251-
# - <tt>force: true</tt> - ignores raised exceptions of Errno::ENOENT
1251+
# - <tt>force: true</tt> - ignores raised exceptions of StandardError
12521252
# and its descendants.
12531253
# - <tt>noop: true</tt> - does not remove entries; returns +nil+.
12541254
# - <tt>secure: true</tt> - removes +src+ securely;
@@ -1315,7 +1315,7 @@ def rm_rf(list, noop: nil, verbose: nil, secure: nil)
13151315
# see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
13161316
#
13171317
# Optional argument +force+ specifies whether to ignore
1318-
# raised exceptions of Errno::ENOENT and its descendants.
1318+
# raised exceptions of StandardError and its descendants.
13191319
#
13201320
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
13211321
#
@@ -1384,12 +1384,10 @@ def remove_entry_secure(path, force = false)
13841384
ent.remove
13851385
rescue
13861386
raise unless force
1387-
raise unless Errno::ENOENT === $!
13881387
end
13891388
end
13901389
rescue
13911390
raise unless force
1392-
raise unless Errno::ENOENT === $!
13931391
end
13941392
module_function :remove_entry_secure
13951393

@@ -1415,7 +1413,7 @@ def fu_stat_identical_entry?(a, b) #:nodoc:
14151413
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
14161414
#
14171415
# Optional argument +force+ specifies whether to ignore
1418-
# raised exceptions of Errno::ENOENT and its descendants.
1416+
# raised exceptions of StandardError and its descendants.
14191417
#
14201418
# Related: FileUtils.remove_entry_secure.
14211419
#
@@ -1425,12 +1423,10 @@ def remove_entry(path, force = false)
14251423
ent.remove
14261424
rescue
14271425
raise unless force
1428-
raise unless Errno::ENOENT === $!
14291426
end
14301427
end
14311428
rescue
14321429
raise unless force
1433-
raise unless Errno::ENOENT === $!
14341430
end
14351431
module_function :remove_entry
14361432

@@ -1441,15 +1437,14 @@ def remove_entry(path, force = false)
14411437
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
14421438
#
14431439
# Optional argument +force+ specifies whether to ignore
1444-
# raised exceptions of Errno::ENOENT and its descendants.
1440+
# raised exceptions of StandardError and its descendants.
14451441
#
14461442
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
14471443
#
14481444
def remove_file(path, force = false)
14491445
Entry_.new(path).remove_file
14501446
rescue
14511447
raise unless force
1452-
raise unless Errno::ENOENT === $!
14531448
end
14541449
module_function :remove_file
14551450

@@ -1461,7 +1456,7 @@ def remove_file(path, force = false)
14611456
# should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
14621457
#
14631458
# Optional argument +force+ specifies whether to ignore
1464-
# raised exceptions of Errno::ENOENT and its descendants.
1459+
# raised exceptions of StandardError and its descendants.
14651460
#
14661461
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
14671462
#

test/fileutils/test_fileutils.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,26 +1822,6 @@ def test_rm_rf
18221822
assert_file_not_exist 'tmpdatadir'
18231823
end
18241824

1825-
def test_rm_rf_no_permissions
1826-
check_singleton :rm_rf
1827-
1828-
return if /mswin|mingw/ =~ RUBY_PLATFORM
1829-
1830-
mkdir 'tmpdatadir'
1831-
touch 'tmpdatadir/tmpdata'
1832-
chmod "-x", 'tmpdatadir'
1833-
1834-
begin
1835-
assert_raise Errno::EACCES do
1836-
rm_rf 'tmpdatadir'
1837-
end
1838-
1839-
assert_file_exist 'tmpdatadir'
1840-
ensure
1841-
chmod "+x", 'tmpdatadir'
1842-
end
1843-
end
1844-
18451825
def test_rmdir
18461826
check_singleton :rmdir
18471827

0 commit comments

Comments
 (0)