python / python/cpython

Don't use O_EXCL when using O_TMPFILE

未關閉
#136,156 13 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-feature
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Feature or enhancement

Proposal:

I was working on a tool on Linux where I'm updating yaml files on disk. I need to replace the file when the data changes. I was looking into using a tempfile created with O_TMPFILE, writing the content, and then replacing the original file using linkat. This would provide a simple atomic replacement of the file without needing to do a lot of file handshaking, etc.

However, at the moment tempfile.TemporaryFile passes the O_EXCL flag to io.open, this prevents the file descriptor from being used in a linkat call.

The TemporaryFile code already removes the O_CREAT flags from the standard open flags when using O_TMPFILE.

Would it be okay to remove O_EXCL from the open flags as well?

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-136281
  • gh-136430
  • gh-136534

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Python 的 tempfile.TemporaryFile 實作開始,檢查使用 O_TMPFILE 時它如何將 flags 傳遞給 io.open。確認只有在此路徑下省略 O_EXCL,然後驗證產生的描述元可以與 linkat 一起使用,同時不改變 TemporaryFile 的其他行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
linux, python
領域
operating-systems
Issue 類型
功能
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。