Skip to content

Commit d87ee27

Browse files
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().
1 parent d7f9c64 commit d87ee27

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/test/support/os_helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ def _rmtree_inner(path):
434434
file=sys.__stderr__)
435435
mode = 0
436436
if stat.S_ISDIR(mode):
437-
_waitfor(_rmtree_inner, fullname, waitall=True)
437+
# Do not follow junctions, which os.lstat() reports
438+
# as directories.
439+
if not os.path.isjunction(fullname):
440+
_waitfor(_rmtree_inner, fullname, waitall=True)
438441
_force_run(fullname, os.rmdir, fullname)
439442
else:
440443
_force_run(fullname, os.unlink, fullname)

0 commit comments

Comments
 (0)