gh-136156: Remove tempfile test_link_tmpfile()#136534
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) |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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.
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.
It's not always possible to guarantee that the file was opened with O_TMPFILE even if tempfile._O_TMPFILE_WORKS is true.