Skip to content

Commit 5b36cf0

Browse files
committed
Document st_birthtime fallback behavior
1 parent d5bc601 commit 5b36cf0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Doc/library/os.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,8 @@ features:
32253225
.. versionchanged:: 3.12
32263226
``st_birthtime`` is now available on Windows.
32273227
.. versionchanged:: next
3228-
``st_birthtime`` is now available on Linux.
3228+
``st_birthtime`` is now present on Linux. The value will be ``0.0``
3229+
on kernel versions < 4.11 or if not supported by the filesystem.
32293230

32303231
.. attribute:: st_birthtime_ns
32313232

@@ -3235,7 +3236,8 @@ features:
32353236

32363237
.. versionadded:: 3.12
32373238
.. versionchanged:: next
3238-
``st_birthtime_ns`` is now available on Linux.
3239+
``st_birthtime_ns`` is now present on Linux. The value will be ``0``
3240+
on kernel versions < 4.11 or if not supported by the filesystem.
32393241

32403242
.. note::
32413243

Modules/posixmodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,10 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
28162816
#elif defined(HAVE_STATX)
28172817
/* We were built with statx support, so stat_result.st_birthtime[_ns]
28182818
exists, but we fell back to stat because statx isn't available at
2819-
runtime. User programs assume st_birthtime is not None. */
2819+
runtime. structseq members are _Py_T_OBJECT (for which NULL means None,
2820+
not AttributeError), but user programs assume st_birthtime is not None.
2821+
When the statx syscall wrapper is available but the syscall itself is
2822+
not, we end up setting the birthtime to 0, so do that here too. */
28202823
SET_ITEM(ST_BIRTHTIME_IDX, PyFloat_FromDouble(0.0));
28212824
SET_ITEM(ST_BIRTHTIME_NS_IDX, _PyLong_GetZero());
28222825
#elif defined(MS_WINDOWS)

0 commit comments

Comments
 (0)