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.

Author eryksun
Recipients Jairo Llopis, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-02-01.21:33:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1612215183.29.0.895300010034.issue43095@roundup.psfhosted.org>
In-reply-to
Content
When an open attempts to access a directory as data, the error code from WinAPI CreateFileW is ERROR_ACCESS_DENIED (5), which maps to C EACCES and thus raises Python PermissionError. 

Python's io.FileIO() type could handle an EACCES error in Windows by checking for a directory. There's a race condition to consider in which an inaccessible file is replaced by a directory, but that seems to be a trivial concern.

io.FileIO() could also use the undocumented _O_OBTAIN_DIR (0x2000) open flag. This opens with backup semantics, which allows opening directories. Then, as already implemented in POSIX, fail with EISDIR if a directory is opened. For example:

    >>> fd = os.open('C:/Temp', 0x2000)
    >>> stat.S_ISDIR(os.fstat(fd).st_mode)
    True
History
Date User Action Args
2021-02-01 21:33:03eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Jairo Llopis
2021-02-01 21:33:03eryksunsetmessageid: <1612215183.29.0.895300010034.issue43095@roundup.psfhosted.org>
2021-02-01 21:33:03eryksunlinkissue43095 messages
2021-02-01 21:33:03eryksuncreate