Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Jul 4, 2025

tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE, so it's possible to use linkat() on the file descriptor.

tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE,
so it's possible to use linkat() on the file descriptor.
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@serhiy-storchaka
Copy link
Member

Could you add a test using the proc filesystem? I tried to implement AT_EMPTY_PATH support (see #89341), but it only works for root.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

self.assertEqual(os.listdir(dir), [])

@unittest.skipUnless(tempfile._O_TMPFILE_WORKS, 'need os.O_TMPFILE')
@unittest.skipUnless(os.path.exists('/proc/self/fd'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe even isdir()?

@serhiy-storchaka
Copy link
Member

!buildbot BSD

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @serhiy-storchaka for commit c912963 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F136281%2Fmerge

The command will test the builders whose names match following regular expression: BSD

The builders matched are:

  • AMD64 FreeBSD PR
  • AMD64 FreeBSD14 PR
  • AMD64 FreeBSD Refleaks PR
  • AMD64 FreeBSD15 PR

@vstinner
Copy link
Member Author

vstinner commented Jul 8, 2025

!buildbot BSD

I tested manually: the test is skipped since os.O_TMPFILE is missing.

@vstinner vstinner merged commit 6c81e8c into python:main Jul 8, 2025
43 of 44 checks passed
@vstinner vstinner deleted the tempfile branch July 8, 2025 16:39
@vstinner
Copy link
Member Author

vstinner commented Jul 8, 2025

Merged, thanks for review @serhiy-storchaka.

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot aarch64 Android 3.x (tier-3) has failed when building commit 6c81e8c.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1594/builds/2820) and take a look at the build logs.
  4. Check if the failure is related to this commit (6c81e8c) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1594/builds/2820

Failed tests:

  • test_tempfile

Failed subtests:

  • test_link_tmpfile - test.test_tempfile.TestTemporaryFile.test_link_tmpfile

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.15/test/test_tempfile.py", line 1614, in test_link_tmpfile
    os.link(f'/proc/self/fd/{fd}',
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
            filename,
            ^^^^^^^^^
            follow_symlinks=True)
            ^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/self/fd/82' -> '/data/user/0/org.python.testbed/cache/tmpd0x9o66s/link'


Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.15/test/test_tempfile.py", line 1614, in test_link_tmpfile
    os.link(f'/proc/self/fd/{fd}',
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
            filename,
            ^^^^^^^^^
            follow_symlinks=True)
            ^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/self/fd/82' -> '/data/user/0/org.python.testbed/cache/tmpmjq3eb8x/link'

@vstinner
Copy link
Member Author

vstinner commented Jul 8, 2025

Oh, the test fails with PermissionError on Android:

ERROR: test_link_tmpfile (test.test_tempfile.TestTemporaryFile.test_link_tmpfile)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.15/test/test_tempfile.py", line 1614, in test_link_tmpfile
    os.link(f'/proc/self/fd/{fd}',
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
            filename,
            ^^^^^^^^^
            follow_symlinks=True)
            ^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/self/fd/82' -> '/data/user/0/org.python.testbed/cache/tmpmjq3eb8x/link'

@vstinner
Copy link
Member Author

vstinner commented Jul 8, 2025

I wrote #136430 to fix the test on Android.

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Android 3.x (tier-3) has failed when building commit 6c81e8c.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1591/builds/2548) and take a look at the build logs.
  4. Check if the failure is related to this commit (6c81e8c) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1591/builds/2548

Failed tests:

  • test_tempfile

Failed subtests:

  • test_link_tmpfile - test.test_tempfile.TestTemporaryFile.test_link_tmpfile

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.15/test/test_tempfile.py", line 1614, in test_link_tmpfile
    os.link(f'/proc/self/fd/{fd}',
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
            filename,
            ^^^^^^^^^
            follow_symlinks=True)
            ^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/self/fd/83' -> '/data/user/0/org.python.testbed/cache/tmprqz0o6wv/link'


Traceback (most recent call last):
  File "/data/user/0/org.python.testbed/files/python/lib/python3.15/test/test_tempfile.py", line 1614, in test_link_tmpfile
    os.link(f'/proc/self/fd/{fd}',
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
            filename,
            ^^^^^^^^^
            follow_symlinks=True)
            ^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/proc/self/fd/83' -> '/data/user/0/org.python.testbed/cache/tmpocwzcriy/link'

@vstinner
Copy link
Member Author

Oh. The test fails on Arch Linux buildbots: https://buildbot.python.org/#/builders/582/builds/6857

ERROR: test_link_tmpfile (test.test_tempfile.TestTemporaryFile.test_link_tmpfile)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.pablogsal-arch-x86_64.asan/build/Lib/test/test_tempfile.py", line 1614, in test_link_tmpfile
    os.link(f'/proc/self/fd/{fd}',
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
            filename,
            ^^^^^^^^^
            follow_symlinks=True)
            ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/proc/self/fd/3' -> '/tmp/test_python_712__99i/tmpgkq51fdc/link'

AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE,
so it's possible to use linkat() on the file descriptor.
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE,
so it's possible to use linkat() on the file descriptor.
picnixz pushed a commit to picnixz/cpython that referenced this pull request Jul 13, 2025
tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE,
so it's possible to use linkat() on the file descriptor.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE,
so it's possible to use linkat() on the file descriptor.
@vstinner
Copy link
Member Author

vstinner commented Aug 5, 2025

Oh. The test fails on Arch Linux buildbots: https://buildbot.python.org/#/builders/582/builds/6857

The buildbot is back to green.

Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
tempfile.TemporaryFile() no longer uses os.O_EXCL with os.O_TMPFILE,
so it's possible to use linkat() on the file descriptor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants