[Python-checkins] cpython: Check for all used fd-based functions in shutil.rmdir, closes #15218
hynek.schlawack
python-checkins at python.org
Fri Jun 29 08:29:31 CEST 2012
http://hg.python.org/cpython/rev/992be49127e1
changeset: 77846:992be49127e1
user: Hynek Schlawack <hs at ox.cx>
date: Fri Jun 29 08:28:20 2012 +0200
summary:
Check for all used fd-based functions in shutil.rmdir, closes #15218
files:
Lib/shutil.py | 6 ++++--
Lib/test/test_shutil.py | 6 +++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -405,8 +405,10 @@
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.
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -524,7 +524,11 @@
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()
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list