[3.13] GH-89727: Partially fix shutil.rmtree() recursion error on deep trees (GH-119634) (#119748)

GH-89727: Partially fix `shutil.rmtree()` recursion error on deep trees (GH-119634)

Make `shutil._rmtree_unsafe()` call `os.walk()`, which is implemented
without recursion.

`shutil._rmtree_safe_fd()` is not affected and can still raise a recursion
error.

(cherry picked from commit a150679f90)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-05-29 22:41:03 +02:00 committed by GitHub
parent c3cfc04a73
commit 061abf8e4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 28 deletions

View file

@ -741,6 +741,17 @@ class TestRmTree(BaseTest, unittest.TestCase):
shutil.rmtree(TESTFN)
raise
@unittest.skipIf(shutil._use_fd_functions, "fd-based functions remain unfixed (GH-89727)")
def test_rmtree_above_recursion_limit(self):
recursion_limit = 40
# directory_depth > recursion_limit
directory_depth = recursion_limit + 10
base = os.path.join(TESTFN, *(['d'] * directory_depth))
os.makedirs(base)
with support.infinite_recursion(recursion_limit):
shutil.rmtree(TESTFN)
class TestCopyTree(BaseTest, unittest.TestCase):