You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to add support for file descriptors pointing to a symlink in os.readlink() . For example:
# setupimportosopen_flags=os.O_RDONLYifhasattr(os, "O_SYMLINK"): # MacOSopen_flags|=os.O_SYMLINKelifhasattr(os, "O_PATH") andhasattr(os, "O_NOFOLLOW"): # Linuxopen_flags|=os.O_PATH|os.O_NOFOLLOWelse:
raiseNotImplementedError("can't get a file descriptor pointing to a symlink on this platform")
fd=os.open("path/to/some/symlink", open_flags)
# the actual new feature: passing a file descriptor for a symlink to os.readlink()link_target=os.readlink(fd)
Of course, you can already read a symlink directly using the path with os.readlink(), and os.readlink() already supports the optional dir_fd parameter, but if all you have if a FD for the symlink itself, right now Python doesn't have a real way to read the symlink.
(As @Rosuav pointed out in the discourse, on Linux you can work around this with os.readlink("", fd), but that solution doesn't work on MacOS.)
Regarding implementation:
On Linux, we simply call readlinkat(fd, "", ..., ...). That should work, according to the man page:
Since Linux 2.6.39, pathname can be an empty string, in which case the
call operates on the symbolic link referred to by dirfd (which should
have been obtained using open(2) with the O_PATH and O_NOFOLLOW flags).
Activity
pythongh-157899: Add support for fds pointing to symlinks in os.readl…
pythongh-157899: Add support for fds pointing to symlinks in os.readl…
pythongh-157899: Add support for fds pointing to symlinks in os.readl…
pythongh-157899: technical: rename HAVE_FREADLINK C macro to _Py_HAVE…
pythongh-157899: fix docs.
pythongh-157899: fix docs.
pythongh-157899: removed unnecessary guard for test.
pythongh-157899: merged upstream/main into feature/pythongh-157899-fd…
pythongh-157899: added iOS as supported platform for calling os.readl…
gh-157899: Add support for fds pointing to symlinks in os.readlink(). (…