[前][次][番号順一覧][スレッド一覧]

ruby-changes:74384

From: Yusuke <ko1@a...>
Date: Mon, 7 Nov 2022 20:25:41 +0900 (JST)
Subject: [ruby-changes:74384] 72c7dba436 (master): [ruby/fileutils] Revert "FileUtils.rm* methods swallows only Errno::ENOENT when force is true"

https://git.ruby-lang.org/ruby.git/commit/?id=72c7dba436

From 72c7dba436a5ebb53dfb37f3e400e84b0c2f9f45 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Tue, 30 Aug 2022 16:02:02 +0900
Subject: [ruby/fileutils] Revert "FileUtils.rm* methods swallows only
 Errno::ENOENT when force is true"

This reverts commit https://github.com/ruby/fileutils/commit/fa65d676ece9.

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

https://github.com/ruby/fileutils/commit/42983c2553
---
 lib/fileutils.rb                 | 17 ++++++-----------
 test/fileutils/test_fileutils.rb | 20 --------------------
 2 files changed, 6 insertions(+), 31 deletions(-)

diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index 745170a121..a33f086a3e 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -1165,7 +1165,7 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1165
   #
   # Keyword arguments:
   #
-  # - <tt>force: true</tt> - ignores raised exceptions of Errno::ENOENT
+  # - <tt>force: true</tt> - ignores raised exceptions of StandardError
   #   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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1248
   #
   # Keyword arguments:
   #
-  # - <tt>force: true</tt> - ignores raised exceptions of Errno::ENOENT
+  # - <tt>force: true</tt> - ignores raised exceptions of StandardError
   #   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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1315
   # see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
   #
   # Optional argument +force+ specifies whether to ignore
-  # raised exceptions of Errno::ENOENT and its descendants.
+  # raised exceptions of StandardError and its descendants.
   #
   # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
   #
@@ -1384,12 +1384,10 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1384
         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
 
@@ -1415,7 +1413,7 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1413
   # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
   #
   # Optional argument +force+ specifies whether to ignore
-  # raised exceptions of Errno::ENOENT and its descendants.
+  # raised exceptions of StandardError and its descendants.
   #
   # Related: FileUtils.remove_entry_secure.
   #
@@ -1425,12 +1423,10 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1423
         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
 
@@ -1441,7 +1437,7 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1437
   # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
   #
   # Optional argument +force+ specifies whether to ignore
-  # raised exceptions of Errno::ENOENT and its descendants.
+  # raised exceptions of StandardError and its descendants.
   #
   # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
   #
@@ -1449,7 +1445,6 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1445
     Entry_.new(path).remove_file
   rescue
     raise unless force
-    raise unless Errno::ENOENT === $!
   end
   module_function :remove_file
 
@@ -1461,7 +1456,7 @@ module FileUtils https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1456
   # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
   #
   # Optional argument +force+ specifies whether to ignore
-  # raised exceptions of Errno::ENOENT and its descendants.
+  # raised exceptions of StandardError and its descendants.
   #
   # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
   #
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index bce7271a3b..05ba8d184a 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -1822,26 +1822,6 @@ cd - https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L1822
     assert_file_not_exist 'tmpdatadir'
   end
 
-  def test_rm_rf_no_permissions
-    check_singleton :rm_rf
-
-    return if /mswin|mingw/ =~ RUBY_PLATFORM
-
-    mkdir 'tmpdatadir'
-    touch 'tmpdatadir/tmpdata'
-    chmod "-x", 'tmpdatadir'
-
-    begin
-      assert_raise Errno::EACCES do
-        rm_rf 'tmpdatadir'
-      end
-
-      assert_file_exist 'tmpdatadir'
-    ensure
-      chmod "+x", 'tmpdatadir'
-    end
-  end
-
   def test_rmdir
     check_singleton :rmdir
 
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]