This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Support st_atim, st_mtim and st_ctim attributes in os.stat_result
Type: enhancement Stage: patch review
Components: Versions: Python 3.3
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, larry, pitrou, r.david.murray, rosslagerwall
Priority: normal Keywords: patch

Created on 2011-04-27 21:00 by Arfrever, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue11941.patch rosslagerwall, 2011-06-03 19:20 patch + doc for issue review
issue11941_2.patch rosslagerwall, 2011-06-08 05:11 version 2 review
Messages (9)
msg134616 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-04-27 21:00
I would like to suggest to add st_atim, st_mtim and st_ctim attributes in os.stat_result objects returned by os.stat(). These attributes would be 2-tuples containing number of seconds and number of nanoseconds. They would expose relevant functionality from libc's stat() and provide better precision than floating-point-based st_atime, st_mtime and st_ctime attributes.

st_atim, st_mtim and st_ctim attributes would be available only if Python has been built on system with libc supporting st_atim, st_mtim and st_ctim in stat structure.

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
msg134643 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-04-28 04:47
I think this is a duplicate of #11457.
msg134679 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-04-28 14:34
Actually issue #11941 should be a dependency of issue #11457. Issue #11941 is only about os.stat(), while issue #11457 proposes changes also in other places (e.g. tarfile module).
msg134691 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-04-28 16:14
Ok, that's true, reopening.
msg137573 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-06-03 19:20
Attached is a patch for review.

It adds st_atim, st_ctim and st_mtim.

They are defined even when the underlying system does not have nanosecond precision.
msg137577 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-06-03 19:54
st_atim, st_mtim and st_ctim were introduced in 2008 version of POSIX (and were earlier provided by glibc as an extension). To avoid compilation failure with some exotic versions of libc, I suggest:
- In configure.in:
AC_CHECK_MEMBERS([struct stat.st_atim])
AC_CHECK_MEMBERS([struct stat.st_ctim])
AC_CHECK_MEMBERS([struct stat.st_mtim])
- In Modules/posixmodule.c:
    PyObject *atim = Py_BuildValue(_STAT_FMT,
                            st->st_atime,
#ifdef HAVE_STRUCT_STAT_ST_ATIM
                            st->st_atim.tv_nsec
#else
                            0
#endif
                            );
...
msg137896 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-06-08 05:11
Here is an updated patch that uses the atim, ctim and mtim variables (which are assigned based on various #ifdefs).

This should now work on Linux, BSD and Windows.
msg137900 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-06-08 11:46
I'm not sure if that's deliberate, but the new attributes don't appear in the result repr():

>>> s = os.stat("LICENSE")
>>> s
posix.stat_result(st_mode=33204, st_ino=524885, st_dev=2053, st_nlink=1, st_uid=500, st_gid=500, st_size=14597, st_atime=1307474138, st_mtime=1299630588, st_ctime=1299630588)
>>> s.st_mtim
(1299630588, 90781883)

In the docs, you also need a "versionchanged" tag to mention that the attributes were added in 3.3.

The patch fails to compile under Windows: MSVC forbids variable declarations after code (atim, ctim, mtim), you have to put them at the beginning of a block. Once this is fixed, it seems to work ok.
msg154404 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-02-26 22:01
Given Guido's rejection of PEP 410, this won't happen, so I'm closing this bug.  Our BFDL has specifically rejected any of the complicated representations; he ruled that all we need are new _ns fields representing the time in nanoseconds, and to accept a "ns=" argument for os.utime and its ilk.  Please see bug #14127 for discussion of that change.
History
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56150
2012-02-26 22:01:36larrysetstatus: open -> closed

nosy: + larry
messages: + msg154404

resolution: wont fix
2011-06-08 11:46:43pitrousetnosy: + pitrou
messages: + msg137900
2011-06-08 05:11:35rosslagerwallsetfiles: + issue11941_2.patch

messages: + msg137896
2011-06-03 19:54:20Arfreversetmessages: + msg137577
2011-06-03 19:20:42rosslagerwallsetfiles: + issue11941.patch
keywords: + patch
messages: + msg137573

stage: patch review
2011-06-03 17:03:51r.david.murraysetnosy: + r.david.murray
2011-04-28 16:15:49rosslagerwalllinkissue11457 dependencies
2011-04-28 16:14:59rosslagerwallsetstatus: closed -> open
resolution: duplicate -> (no value)
messages: + msg134691
2011-04-28 14:34:21Arfreversetmessages: + msg134679
2011-04-28 04:47:27rosslagerwallsetstatus: open -> closed

nosy: + rosslagerwall
messages: + msg134643

resolution: duplicate
2011-04-27 21:00:15Arfrevercreate