Message386117
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 |
|
Date |
User |
Action |
Args |
2021-02-01 21:33:03 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower, Jairo Llopis |
2021-02-01 21:33:03 | eryksun | set | messageid: <1612215183.29.0.895300010034.issue43095@roundup.psfhosted.org> |
2021-02-01 21:33:03 | eryksun | link | issue43095 messages |
2021-02-01 21:33:03 | eryksun | create | |
|