gh-156707: Do not follow junctions in os_helper.rmtree() on Windows - #156710
Conversation
…dows 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().
For
For lstat = srcentry.stat(follow_symlinks=False)
if lstat.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT:
is_symlink = FalseSo yeah, fixing |
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Checking for isjunction() to decide if we should do a recursive call is the right fix.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-156714 is a backport of this pull request to the 3.15 branch. |
|
GH-156715 is a backport of this pull request to the 3.14 branch. |
|
GH-156716 is a backport of this pull request to the 3.13 branch. |
…ndows (GH-156710) (GH-156716) 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>
…ndows (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>
|
|
…ndows (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 d87ee27) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
os.lstat()reports a junction as a directory, soos_helper.rmtree()descended into junctions and could remove files outside of the removed tree.os.walk()andshutil.rmtree()already skip junctions, so this only makesos_helper.rmtree()agree with them.