Repository navigation
gh-157899: Add support for fds pointing to symlinks in os.readlink(). #157915
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
Changes from 1 commit
2cbd30e
8bb6f09
8196b59
f96963a
7b566b7
253c3b4
20fa1e2
6c8f5f1
9bf9236
c8d85a6
83fcbf4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… feedback from MR. * os.readlink() now returns a `str` (rather than `bytes`) when called with a file descriptor. * os.readlink now added to `os.supports_fd` on the platforms where this feature is supported. * Small refactor inside `os.readlink`: drop *_unavailable variables, generate error messages inline. Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS around each syscall site. * Docs: Android is now mentioned as supported platform for this feature in all relevant places.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1908,14 +1908,19 @@ def test_readlink_with_fd(self): | |||||||
| self.addCleanup(posix.unlink, fullname) | ||||||||
| fd = self._open_symlink_as_fd(fullname) | ||||||||
| self.addCleanup(os.close, fd) | ||||||||
| self.assertEqual(os.readlink(fd), b"symlink") | ||||||||
| self.assertEqual(os.readlink(fd), "symlink") | ||||||||
|
|
||||||||
| @unittest.skipUnless(_support_readlink_with_fd, | ||||||||
| "feature not supported on this platform") | ||||||||
| def test_readlink_with_fd_not_referring_to_symlink_throws(self): | ||||||||
| with self.prepare_file() as (dir_fd, name, fullname): | ||||||||
| fd = os.open(fullname, os.O_RDONLY) | ||||||||
| self.addCleanup(os.close, fd) | ||||||||
| # on Linux/Android, readlinkat("", fd, ...) fails with ENOENT, which | ||||||||
| # Python translates to a FileNotFoundError, a subclass of OSError. | ||||||||
| # On MacOS, freadlink(fd, ...) fails with EINVAL, which gets raised | ||||||||
| # as a OSError. | ||||||||
| # So catching OSError here covers both cases. | ||||||||
| with self.assertRaises(OSError): | ||||||||
|
encukou marked this conversation as resolved.
|
||||||||
| os.readlink(fd) | ||||||||
|
|
||||||||
|
|
@@ -1942,6 +1947,11 @@ def test_readlink_with_fd_throws_not_implemented_error(self): | |||||||
| with self.assertRaises(NotImplementedError): | ||||||||
| os.readlink(fd) | ||||||||
|
encukou marked this conversation as resolved.
|
||||||||
|
|
||||||||
| @unittest.skipUnless(hasattr(os, "supports_fd") and hasattr(os, "readlink"), | ||||||||
| "feature not supported on this platform") | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to other tests,
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed this comment. I just pushed an update: 6c8f5f1 Originally I wanted to be careful (because the |
||||||||
| def test_readlink_is_in_supports_fd_on_supported_platforms(self): | ||||||||
| self.assertEqual(os.readlink in os.supports_fd, self._support_readlink_with_fd) | ||||||||
|
|
||||||||
| @unittest.skipUnless(os.rename in os.supports_dir_fd, "test needs dir_fd support in os.rename()") | ||||||||
| def test_rename_dir_fd(self): | ||||||||
| with self.prepare_file() as (dir_fd, name, fullname), \ | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.