-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-136156: Remove tempfile test_link_tmpfile() #136534
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
Conversation
It's not always possible to guarantee that the file was opened with O_TMPFILE even if tempfile._O_TMPFILE_WORKS is true.
The test fails on Arch Linux: #136281 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is removing the test the only way? Can we check _O_TMPFILE_WORKS
after calling TemporaryFile()
?
The test already checks _O_TMPFILE_WORKS after TemporaryFile(): with tempfile.TemporaryFile('w', dir=dir) as tmp:
# the flag can become False on Linux <= 3.11
if not tempfile._O_TMPFILE_WORKS:
self.skipTest("O_TMPFILE doesn't work") The problem is that TemporaryFile() doesn't set _O_TMPFILE_WORKS to False on OSError (other than IsADirectoryError), it only ignores the error silently. |
I removed the test. It can be added back if someone finds a clever trick to check if O_TMPFILE was used or not. I don't know how to query open flags from a file descriptor. |
What was that error? Why |
I don't have access to the buildbot, so I don't know. But I suspect that we hit this code path: except OSError:
# The filesystem of the directory does not support O_TMPFILE.
# For example, OSError(95, 'Operation not supported').
#
# On Linux kernel older than 3.11, trying to open a regular
# file (or a symbolic link to a regular file) with O_TMPFILE
# fails with NotADirectoryError, because O_TMPFILE is read as
# O_DIRECTORY.
pass
# Fallback to _mkstemp_inner(). Later, linkat() fails with FileNotFoundError: #136281 (comment) |
Example trying to call linkat() whereas O_TMPFILE is not used: import os, tempfile
dir = '.'
flags = os.O_RDWR | os.O_CREAT | os.O_EXCL
fd, name = tempfile._mkstemp_inner(dir, "tmp", "", flags, str)
os.unlink(name)
try:
os.link(f'/proc/self/fd/{fd}', 'link', follow_symlinks=True)
finally:
os.close(fd) It fails with:
|
There may be a bug in |
It's not always possible to guarantee that the file was opened with O_TMPFILE even if tempfile._O_TMPFILE_WORKS is true.
It's not always possible to guarantee that the file was opened with O_TMPFILE even if tempfile._O_TMPFILE_WORKS is true.