[New-bugs-announce] [issue33010] os.path.isdir() returns True for broken directory symlinks or junctions
Alexey Izbyshev
report at bugs.python.org
Tue Mar 6 04:47:34 EST 2018
New submission from Alexey Izbyshev <izbyshev at ispras.ru>:
os.path.isdir() violates its own documentation by returning True for broken directory symlinks or junctions, for which os.path.exists() returns False:
>>> os.mkdir('b')
>>> import _winapi
>>> _winapi.CreateJunction('b', 'a')
>>> os.rmdir('b')
>>> os.path.exists('a')
False
>>> os.path.isdir('a')
True
The underlying problem is that os.path.isdir() uses GetFileAttributes, which is documented not to follow symlinks.
Eryk, is there a cheaper way to check FILE_ATTRIBUTE_DIRECTORY on a path while following reparse points apart from CreateFile/GetFileInformationByHandleEx/CloseFile?
Also, does it make sense to use GetFileAttributes as a fast path and use something like above as a fallback only if FILE_ATTRIBUTE_REPARSE_POINT is set, or does GetFileAttributes do something equivalently expensive under the hood?
----------
components: Extension Modules, Windows
messages: 313314
nosy: eryksun, izbyshev, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: os.path.isdir() returns True for broken directory symlinks or junctions
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33010>
_______________________________________
More information about the New-bugs-announce
mailing list