Skip to content

Commit 60138de

Browse files
[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 d87ee27) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent ec7c6a0 commit 60138de

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
@@ -433,7 +433,10 @@ def _rmtree_inner(path):
433433
file=sys.__stderr__)
434434
mode = 0
435435
if stat.S_ISDIR(mode):
436-
_waitfor(_rmtree_inner, fullname, waitall=True)
436+
# Do not follow junctions, which os.lstat() reports
437+
# as directories.
438+
if not os.path.isjunction(fullname):
439+
_waitfor(_rmtree_inner, fullname, waitall=True)
437440
_force_run(fullname, os.rmdir, fullname)
438441
else:
439442
_force_run(fullname, os.unlink, fullname)

0 commit comments

Comments
 (0)