[3.12] GH-89727: Fix shutil.rmtree() recursion error on deep trees (GH-119808) (#119919)

Implement `shutil._rmtree_safe_fd()` using a list as a stack to avoid emitting recursion errors on deeply nested trees.

`shutil._rmtree_unsafe()` was fixed in a150679f90.

(cherry picked from commit 53b1981fb0)
This commit is contained in:
Barney Gale 2024-06-01 20:39:35 +01:00 committed by GitHub
parent 60393f5f14
commit feb7870b46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 89 deletions

View file

@ -686,7 +686,6 @@ class TestRmTree(BaseTest, unittest.TestCase):
shutil.rmtree(TESTFN)
self.assertFalse(os.path.exists(TESTFN))
@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