https://github.com/python/cpython/commit/d87ee279a1f6dfdb478ede5f0ba0360123d85916
commit: d87ee279a1f6dfdb478ede5f0ba0360123d85916
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-08-31T14:11:29Z
summary:
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().
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]