python / python/cpython

Don't use O_EXCL when using O_TMPFILE

Offen
#136,156 13 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei Pythons Implementierung von tempfile.TemporaryFile und untersuche, wie sie Flags an io.open übergibt, wenn O_TMPFILE verwendet wird. Bestätige, dass O_EXCL nur für diesen Pfad weggelassen wird, und überprüfe anschließend, dass der resultierende Deskriptor mit linkat verwendet werden kann, ohne das sonstige Verhalten von TemporaryFile zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
linux, python
Bereich
operating-systems
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.