diff options
author | Gregory P. Smith <greg@krypto.org> | 2012-06-24 07:24:31 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2012-06-24 07:24:31 (GMT) |
commit | 853ef475228e6fb9683209b361878e8f610e3762 (patch) | |
tree | 76c1bb1b08695b15c8206f49c8681f560b131d34 /Lib | |
parent | 990a5feba77de7fc5fd5ad5a16f61dc93667f63e (diff) | |
parent | 430d7a3090389606c2c9370d854a08eacc7f6823 (diff) | |
download | cpython-853ef475228e6fb9683209b361878e8f610e3762.zip cpython-853ef475228e6fb9683209b361878e8f610e3762.tar.gz cpython-853ef475228e6fb9683209b361878e8f610e3762.tar.bz2 |
merge heads
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/shutil.py | 8 | ||||
-rw-r--r-- | Lib/test/test_shutil.py | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index f743d05..2c00f4a 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -405,8 +405,9 @@ def _rmtree_safe_fd(topfd, path, onerror): except os.error: onerror(os.rmdir, path, sys.exc_info()) -rmtree_is_safe = _use_fd_functions = (os.unlink in os.supports_dir_fd and - os.open in os.supports_dir_fd) +_use_fd_functions = (os.unlink in os.supports_dir_fd and + os.open in os.supports_dir_fd) + def rmtree(path, ignore_errors=False, onerror=None): """Recursively delete a directory tree. @@ -449,6 +450,9 @@ def rmtree(path, ignore_errors=False, onerror=None): else: return _rmtree_unsafe(path, onerror) +# Allow introspection of whether or not the hardening against symlink +# attacks is supported on the current platform +rmtree.avoids_symlink_attacks = _use_fd_functions def _basename(path): # A basename() variant which first strips the trailing slash, if present. diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index b2ac0cf..067889e 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -487,7 +487,7 @@ class TestShutil(unittest.TestCase): 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: self.assertTrue(shutil._use_fd_functions) - self.assertTrue(shutil.rmtree_is_safe) + self.assertTrue(shutil.rmtree.avoids_symlink_attacks) tmp_dir = self.mkdtemp() d = os.path.join(tmp_dir, 'a') os.mkdir(d) @@ -502,7 +502,7 @@ class TestShutil(unittest.TestCase): shutil._rmtree_safe_fd = real_rmtree else: self.assertFalse(shutil._use_fd_functions) - self.assertFalse(shutil.rmtree_is_safe) + self.assertFalse(shutil.rmtree.avoids_symlink_attacks) def test_rmtree_dont_delete_file(self): # When called on a file instead of a directory, don't delete it. |