[3.12] gh-79325: Fix recursion error in TemporaryDirectory cleanup on… · python/cpython@34e9e20 · GitHub
Skip to content

Commit 34e9e20

Browse files
[3.12] gh-79325: Fix recursion error in TemporaryDirectory cleanup on Windows (GH-112762) (GH-112847)
(cherry picked from commit b2923a6) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 418adf6 commit 34e9e20

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lib/tempfile.py

Lines changed: 8 additions & 2 deletions

Lib/test/test_tempfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,17 @@ def test_explicit_cleanup_correct_error(self):
16511651
with self.assertRaises(PermissionError):
16521652
temp_dir.cleanup()
16531653

1654+
@unittest.skipUnless(os.name == "nt", "Only on Windows.")
1655+
def test_cleanup_with_used_directory(self):
1656+
with tempfile.TemporaryDirectory() as working_dir:
1657+
temp_dir = self.do_create(dir=working_dir)
1658+
subdir = os.path.join(temp_dir.name, "subdir")
1659+
os.mkdir(subdir)
1660+
with os_helper.change_cwd(subdir):
1661+
# Previously raised RecursionError on some OSes
1662+
# (e.g. Windows). See bpo-35144.
1663+
with self.assertRaises(PermissionError):
1664+
temp_dir.cleanup()
16541665

16551666
@os_helper.skip_unless_symlink
16561667
def test_cleanup_with_symlink_to_a_directory(self):
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)