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.

classification
Title: os.listdir is missing in os.supports_dir_fd
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: larry Nosy List: Arfrever, georg.brandl, hynek, larry, pitrou, serhiy.storchaka
Priority: release blocker Keywords:

Created on 2012-06-28 12:04 by hynek, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (11)
msg164249 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-06-28 12:04
>>> n = os.open('/tmp', os.O_RDONLY)
>>> l = os.listdir(n)
>>> os.listdir in os.supports_dir_fd
False
msg164290 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-06-28 20:03
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).
msg164291 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-06-28 20:23
I don't really care about the name but I'd really like some way to check whether listdir supports fds.
msg164292 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-06-28 20:38
Like I said: use os.supports_fd.
msg164294 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-06-28 21:12
Ah sorry, that wasn't in the mail (stupid >>>).
msg164301 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-06-28 23:50
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 #15176.
msg164314 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-06-29 05:58
> I proposed making os.listdir accept dir_fd, and internally use open and listdir to emulate the behavior.

Hmm, I understood the issue as the request for adding dir_fd argument to
os.listdir. openat+fdopendir+readdir+closedir+close or, in Python,

def listdir2(path, dir_fd=None):
    fd = os.open(path, dir_fd)
    try:
        return os.listdir(fd)
    finally:
        os.close(fd)

>   But someone (Antoine?) rightly pointed out, this would break the guideline that POSIX os.* functions on Unix-y OSes are atomic.

os.listdir is not atomic. opendir+readdir+closedir+close or fdup
+fdopendir+readdir+closedir+close.
msg164315 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-06-29 06:25
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.
msg164317 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-06-29 06:32
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.
msg164318 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-06-29 07:20
> 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.

I know that this is possible (and relatively easy), but I don't think
it's useful. If you use at-functions, then after listdir should be
at-function, and for this purpose you need to get directory's fd in any
case. I don't see useful use cases for listdir(name, dir_fd). So I'm not
going to open a new issue and I'm happy with closing this one.
msg164319 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-06-29 08:24
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!
History
Date User Action Args
2022-04-11 14:57:32adminsetnosy: + georg.brandl
github: 59422
2012-06-29 08:24:25larrysetmessages: + msg164319
2012-06-29 07:20:46serhiy.storchakasetmessages: + msg164318
2012-06-29 06:32:45hyneksetmessages: + msg164317
2012-06-29 06:25:43larrysetnosy: + pitrou
messages: + msg164315
2012-06-29 05:58:22serhiy.storchakasetmessages: + msg164314
2012-06-28 23:50:37larrysetstatus: open -> closed
resolution: not a bug
messages: + msg164301

stage: needs patch -> resolved
2012-06-28 21:12:43hyneksetmessages: + msg164294
2012-06-28 20:38:04larrysetmessages: + msg164292
2012-06-28 20:23:35hyneksetmessages: + msg164291
2012-06-28 20:03:45larrysetmessages: + msg164290
2012-06-28 18:26:18Arfreversetnosy: + Arfrever
2012-06-28 14:36:11hyneklinkissue15218 dependencies
2012-06-28 14:20:54serhiy.storchakasetnosy: + serhiy.storchaka
2012-06-28 12:04:20hynekcreate