Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0f6e0a

Browse files
committed
Check for all used fd-based functions in shutil.rmdir, closes #15218
1 parent 0b50bf3 commit d0f6e0a

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/shutil.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,10 @@ def _rmtree_safe_fd(topfd, path, onerror):
405405
except os.error:
406406
onerror(os.unlink, fullname, sys.exc_info())
407407

408-
_use_fd_functions = (os.unlink in os.supports_dir_fd and
409-
os.open in os.supports_dir_fd)
408+
_use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
409+
os.supports_dir_fd and
410+
os.listdir in os.supports_fd and
411+
os.stat in os.supports_follow_symlinks)
410412

411413
def rmtree(path, ignore_errors=False, onerror=None):
412414
"""Recursively delete a directory tree.

Lib/test/test_shutil.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,11 @@ def test_copyfile_symlinks(self):
524524
self.assertFalse(os.path.islink(dst))
525525

526526
def test_rmtree_uses_safe_fd_version_if_available(self):
527-
if os.unlink in os.supports_dir_fd and os.open in os.supports_dir_fd:
527+
_use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
528+
os.supports_dir_fd and
529+
os.listdir in os.supports_fd and
530+
os.stat in os.supports_follow_symlinks)
531+
if _use_fd_functions:
528532
self.assertTrue(shutil._use_fd_functions)
529533
self.assertTrue(shutil.rmtree.avoids_symlink_attacks)
530534
tmp_dir = self.mkdtemp()

0 commit comments

Comments
 (0)