https://github.com/python/cpython/commit/60138de699a6fc8e180267bce3fa6188208283c6
commit: 60138de699a6fc8e180267bce3fa6188208283c6
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-08-31T14:37:55Z
summary:

[3.14] gh-156707: Do not follow junctions in os_helper.rmtree() on Windows 
(GH-156710) (GH-156715)

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 daf6060940e97f0..36d2fa94c61d4f4 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -433,7 +433,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]

Reply via email to