Eryk Sun <eryk...@gmail.com> added the comment:
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 ---------- components: +IO nosy: +eryksun type: -> behavior _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43095> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com