]> granicus.if.org Git - python/commitdiff
Check for all used fd-based functions in shutil.rmdir, closes #15218
authorHynek Schlawack <hs@ox.cx>
Fri, 29 Jun 2012 06:28:20 +0000 (08:28 +0200)
committerHynek Schlawack <hs@ox.cx>
Fri, 29 Jun 2012 06:28:20 +0000 (08:28 +0200)
Lib/shutil.py
Lib/test/test_shutil.py

index 99e4017d860da229ab291831fe945a120a3503eb..6d80feed673066deeb757afd958752b1d07cdd4e 100644 (file)
@@ -405,8 +405,10 @@ def _rmtree_safe_fd(topfd, path, onerror):
             except os.error:
                 onerror(os.unlink, fullname, sys.exc_info())
 
-_use_fd_functions = (os.unlink in os.supports_dir_fd and
-                     os.open in os.supports_dir_fd)
+_use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
+                     os.supports_dir_fd and
+                     os.listdir in os.supports_fd and
+                     os.stat in os.supports_follow_symlinks)
 
 def rmtree(path, ignore_errors=False, onerror=None):
     """Recursively delete a directory tree.
index cb712b3e61695198aa8cba2b68f5b1e27fb42e69..a2b6e88afec0ef37bd53cc83134779f4b702a0f2 100644 (file)
@@ -524,7 +524,11 @@ class TestShutil(unittest.TestCase):
         self.assertFalse(os.path.islink(dst))
 
     def test_rmtree_uses_safe_fd_version_if_available(self):
-        if os.unlink in os.supports_dir_fd and os.open in os.supports_dir_fd:
+        _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
+                             os.supports_dir_fd and
+                             os.listdir in os.supports_fd and
+                             os.stat in os.supports_follow_symlinks)
+        if _use_fd_functions:
             self.assertTrue(shutil._use_fd_functions)
             self.assertTrue(shutil.rmtree.avoids_symlink_attacks)
             tmp_dir = self.mkdtemp()