This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: support.rmtree fails on symlinks under Windows
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brian.curtin Nosy List: brian.curtin, jkloth, pitrou, python-dev, r.david.murray, steve.dower, tim.golden, vstinner
Priority: normal Keywords: patch

Created on 2013-11-16 21:23 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
symlink.patch jkloth, 2013-11-27 18:56 review
Messages (8)
msg203085 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-16 21:23
support.rmtree doesn't work under Windows when there are symlinks (the symlinks aren't deleted anymore), while shutil.rmtree() works fine:

>>> support.rmtree("@test_2160_tmp")
>>> os.listdir("@test_2160_tmp")
['dirA', 'dirB', 'dirC', 'fileA', 'linkA', 'linkB']
>>> shutil.rmtree("@test_2160_tmp")
>>> os.listdir("@test_2160_tmp")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 3] The system cannot find the path specified: '@test_2160_tmp'

This breaks the pathlib tests under Windows with symlink privileges held.
msg203086 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-16 21:25
shutil.rmtree() uses os.lstat() while support.rmtree() calls os.path.isdir() instead.
msg204236 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-24 17:05
Note that using shutil.rmtree() means there are sporadic test_pathlib failures under Windows:
http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/3436/steps/test/logs/stdio
msg204607 - (view) Author: Jeremy Kloth (jkloth) * Date: 2013-11-27 18:56
The attached patch changes support.rmtree to use os.lstat() instead of the builtin _isdir() to test for directory-ness of a path.
msg204609 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-27 20:34
Why not starting to use pathlib? pathlib.Path(path).resolve().is_dir().
msg204612 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-27 21:04
> Why not starting to use pathlib? pathlib.Path(path).resolve().is_dir().

I would rather keep using low-level APIs in test support functions.
msg223590 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-21 17:20
New changeset 28bb1aa9ca3d by Victor Stinner in branch '3.4':
Issue #19629: Fix support.rmtree(), use os.lstat() to check if the file is a
http://hg.python.org/cpython/rev/28bb1aa9ca3d

New changeset e405bcbf761c by Victor Stinner in branch 'default':
Merge Python 3.4
http://hg.python.org/cpython/rev/e405bcbf761c
msg223602 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-21 19:41
New changeset c026ed24a211 by Victor Stinner in branch '3.4':
Issue #19629: Add missing "import stat"
http://hg.python.org/cpython/rev/c026ed24a211

New changeset 168cd3d19fef by Victor Stinner in branch 'default':
(Merge 3.4) Issue #19629: Add missing "import stat"
http://hg.python.org/cpython/rev/168cd3d19fef
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63828
2014-07-22 03:57:00berker.peksagsetstatus: open -> closed
stage: needs patch -> resolved
resolution: fixed
versions: + Python 3.5, - Python 3.3
2014-07-21 19:41:08python-devsetmessages: + msg223602
2014-07-21 17:20:28python-devsetnosy: + python-dev
messages: + msg223590
2014-07-21 17:07:13zach.warelinkissue22022 superseder
2013-11-27 21:04:48pitrousetmessages: + msg204612
2013-11-27 20:34:48vstinnersetmessages: + msg204609
2013-11-27 18:56:22jklothsetfiles: + symlink.patch
keywords: + patch
messages: + msg204607
2013-11-27 14:20:49vstinnersetnosy: + vstinner
2013-11-27 13:45:48pitroulinkissue19811 superseder
2013-11-25 03:26:26ezio.melottisetnosy: + r.david.murray
2013-11-24 17:05:47pitrousetnosy: + steve.dower
messages: + msg204236
2013-11-17 17:29:43jklothsetnosy: + jkloth
2013-11-16 21:25:27pitrousetmessages: + msg203086
2013-11-16 21:23:12pitroucreate