New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os.listdir is missing in os.supports_dir_fd #59422
Comments
>>> n = os.open('/tmp', os.O_RDONLY)
>>> l = os.listdir(n)
>>> os.listdir in os.supports_dir_fd
False |
I want to mark this as wontfix. >>> os.listdir in os.supports_fd
True The concept we're struggling with here: is the "fd" you pass in to os.listdir a "dir_fd"? I claim that it isn't. I'm trying to enforce the concept, in both the documentation and the code, that "dir_fd" is a directory fd *accompanying a path*. With listdir, it isn't accompanied by a path, it replaces the path. So I suggest it's not a "dir_fd", it's just an "fd" which by sheer coincidence happens to reference a directory. I proposed making os.listdir accept dir_fd, and internally use open and listdir to emulate the behavior. But someone (Antoine?) rightly pointed out, this would break the guideline that POSIX os.* functions on Unix-y OSes are atomic. I might go so far as to say this needs a documentation fix. But I won't condone any sort of code fix (like adding os.listdir to os.supports_dir_fd). |
I don't really care about the name but I'd really like some way to check whether listdir supports fds. |
Like I said: use os.supports_fd. |
Ah sorry, that wasn't in the mail (stupid >>>). |
I'm closing this. os.listdir should not be listed in supports_dir_fd, because it has no dir_fd parameter. For reference, we discussed all this previously in issue bpo-15176. |
Hmm, I understood the issue as the request for adding dir_fd argument to def listdir2(path, dir_fd=None):
fd = os.open(path, dir_fd)
try:
return os.listdir(fd)
finally:
os.close(fd)
os.listdir is not atomic. opendir+readdir+closedir+close or fdup |
Storchaka: please take it up with Antoine, he's the defender of the realm for POSIX-functions-are-atomic iirc. I'd be happy with dir_fd for os.listdir, though it may be too late for 3.3 anyway. |
Just in my defense: Larry suggested in msg164245 to me to check for listdir in supports_dir_fd so I just assumed it's broken as it didn't work. I'm totally fine with the current behavior, the discussion about dir_fd support in listdir isn't what I intended with this ticket. |
I know that this is possible (and relatively easy), but I don't think |
WFM. That is, unless people want to bring up additional only-tangentially-related topics to annoy Hynek ;-) How about those <local sports team>? They're really having a year of it, aren't they! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: