https://github.com/python/cpython/commit/b93576a2b66d98ec8fe2bf64de6fd27a7851e1ed commit: b93576a2b66d98ec8fe2bf64de6fd27a7851e1ed branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: hugovk <[email protected]> date: 2026-08-31T22:05:08+03:00 summary:
[3.15] gh-156707: Do not follow junctions in os_helper.rmtree() on Windows (GH-156710) (#156714) gh-156707: Do not follow junctions in os_helper.rmtree() on Windows (GH-156710) os.lstat() reports a junction as a directory, so the junction was followed and files in the directory it points to could be removed. Now the junction itself is removed, as in os.walk() and shutil.rmtree(). (cherry picked from commit d87ee279a1f6dfdb478ede5f0ba0360123d85916) Co-authored-by: Serhiy Storchaka <[email protected]> files: M Lib/test/support/os_helper.py diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py index e1e2e69cb3d8334..12d34dedfe1bbaa 100644 --- a/Lib/test/support/os_helper.py +++ b/Lib/test/support/os_helper.py @@ -434,7 +434,10 @@ def _rmtree_inner(path): file=sys.__stderr__) mode = 0 if stat.S_ISDIR(mode): - _waitfor(_rmtree_inner, fullname, waitall=True) + # Do not follow junctions, which os.lstat() reports + # as directories. + if not os.path.isjunction(fullname): + _waitfor(_rmtree_inner, fullname, waitall=True) _force_run(fullname, os.rmdir, fullname) else: _force_run(fullname, os.unlink, fullname) _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
