[issue29366] os.listdir has inconsistent behavior when run on a non-directory
Eryk Sun
report at bugs.python.org
Sun Jun 18 19:57:13 EDT 2017
Eryk Sun added the comment:
Yes, I think this issue should be closed. But for the record I'd like to note a not uncommon case in which listdir() raise FileNotFoundError on Windows.
According to MS-FSA [1], if a request to open a directory resolves to a file, the operation should fail with STATUS_NOT_A_DIRECTORY (see 2.1.5.1, phase 7). That's the scenario I was discussing in previous messages. However, I neglected to discuss what happens when an intermediate path component is not a directory. In theory this case should also fail with STATUS_NOT_A_DIRECTORY (see 2.1.5.1, phase 6). However, in practice MS file systems instead return STATUS_OBJECT_PATH_NOT_FOUND, which becomes ERROR_PATH_NOT_FOUND, for which Python raises FileNotFoundError.
Walking the path to find the reason for the failure shouldn't be attempted because it's subject to race conditions -- e.g. the file that caused the failure may no longer exist.
[1]: https://msdn.microsoft.com/en-us/library/ff469536.aspx
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29366>
_______________________________________
More information about the Python-bugs-list
mailing list