Skip to content

Support st_atim, st_mtim and st_ctim attributes in os.stat_result #56150

Closed

Description

@Arfrever
mannequin
BPO 11941
Nosy @pitrou, @larryhastings, @bitdancer
Files
  • issue11941.patch: patch + doc for issue
  • issue11941_2.patch: version 2
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-26.22:01:36.328>
    created_at = <Date 2011-04-27.21:00:15.746>
    labels = ['type-feature']
    title = 'Support st_atim, st_mtim and st_ctim attributes in os.stat_result'
    updated_at = <Date 2012-02-26.22:01:36.326>
    user = 'https://bugs.python.org/Arfrever'

    bugs.python.org fields:

    activity = <Date 2012-02-26.22:01:36.326>
    actor = 'larry'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-26.22:01:36.328>
    closer = 'larry'
    components = []
    creation = <Date 2011-04-27.21:00:15.746>
    creator = 'Arfrever'
    dependencies = []
    files = ['22237', '22279']
    hgrepos = []
    issue_num = 11941
    keywords = ['patch']
    message_count = 9.0
    messages = ['134616', '134643', '134679', '134691', '137573', '137577', '137896', '137900', '154404']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'larry', 'Arfrever', 'r.david.murray', 'rosslagerwall']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue11941'
    versions = ['Python 3.3']

    Activity

    1. Arfrever commented on Apr 27, 2011

      Arfrevermannequin
      MannequinAuthor

      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

    2. rosslagerwall commented on Apr 28, 2011

      rosslagerwallmannequin
      Mannequin

      I think this is a duplicate of bpo-11457.

    3. Arfrever commented on Apr 28, 2011

      Arfrevermannequin
      MannequinAuthor

      Actually issue bpo-11941 should be a dependency of issue bpo-11457. Issue bpo-11941 is only about os.stat(), while issue bpo-11457 proposes changes also in other places (e.g. tarfile module).

    4. rosslagerwall commented on Apr 28, 2011

      rosslagerwallmannequin
      Mannequin

      Ok, that's true, reopening.

    5. rosslagerwall commented on Jun 3, 2011

      rosslagerwallmannequin
      Mannequin

      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.

    6. Arfrever commented on Jun 3, 2011

      Arfrevermannequin
      MannequinAuthor
      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
                                  );
      ...
    7. rosslagerwall commented on Jun 8, 2011

      rosslagerwallmannequin
      Mannequin

      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.

    8. pitrou commented on Jun 8, 2011

      @pitrou
      Member

      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.

    9. larryhastings commented on Feb 26, 2012

      @larryhastings
      Contributor

      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 bpo-14127 for discussion of that change.

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions