Skip to content

Commit 9aba8c8

Browse files
committed
Issue #21515: Elaborate tempfile.TemporaryFile() comment
Explain why calling os.open() with os.O_TMPFILE is a safe test to check if O_TMPFILE is supported by the running kernel.
1 parent d17427b commit 9aba8c8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

Lib/tempfile.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,20 @@ def TemporaryFile(mode='w+b', buffering=-1, encoding=None,
591591
flags2 = (flags | _os.O_TMPFILE) & ~_os.O_CREAT
592592
fd = _os.open(dir, flags2, 0o600)
593593
except IsADirectoryError:
594-
# Linux kernel older than 3.11 ignores O_TMPFILE flag.
595-
# Set flag to False to not try again.
594+
# Linux kernel older than 3.11 ignores the O_TMPFILE flag:
595+
# O_TMPFILE is read as O_DIRECTORY. Trying to open a directory
596+
# with O_RDWR|O_DIRECTORY fails with IsADirectoryError, a
597+
# directory cannot be open to write. Set flag to False to not
598+
# try again.
596599
_O_TMPFILE_WORKS = False
597600
except OSError:
598601
# The filesystem of the directory does not support O_TMPFILE.
599602
# For example, OSError(95, 'Operation not supported').
603+
#
604+
# On Linux kernel older than 3.11, trying to open a regular
605+
# file (or a symbolic link to a regular file) with O_TMPFILE
606+
# fails with NotADirectoryError, because O_TMPFILE is read as
607+
# O_DIRECTORY.
600608
pass
601609
else:
602610
try:

0 commit comments

Comments
 (0)