New submission from Larry Hastings <la...@hastings.org>:

Since Linux 2.5 stat() has supported reading nanosecond resolution (1b/sec) for 
atime and mtime.  However, the utime() family of functions could only write 
atime and mtime with microsecond resolution (1m/sec) until relatively recently.

On POSIX platforms Python reads atime and mtime at nanosecond resolution but 
only writes them at microsecond resolution.  This impedance mismatch can cause 
undesirable behavior.  Consider the following code:

    import os
    import shutil
    import sys

    def mtime(path):
      return os.stat(path).st_mtime

    src = sys.argv[0]
    dest = src + ".new"
    shutil.copy2(src, dest)
    assert mtime(src) == mtime(dest)

When run under Python on any modern Linux system, the assert fails.  (I think 
any Python since 2.5 will do; I tested with 2.7.1 and a fresh 3.3 trunk.)

The accompanying patch modifies Modules/posixmodule.c so all functions that 
write atime and mtime use nanosecond resolution when possible.  With this patch 
applied, all the regression tests pass (except the ones for extension modules I 
didn't compile), and the above code runs to completion.

Happy to hoist the patch up on Rietveld if there's interest.

p.s. I have the commit bit set, so I'd like to be the one to check this in if 
we get that far.

----------
assignee: larry
components: Extension Modules
files: larry.utimensat.patch.r1
messages: 143563
nosy: larry
priority: normal
severity: normal
status: open
title: Change os.utime &c functions to use nanosecond precision where possible
type: feature request
versions: Python 3.3
Added file: http://bugs.python.org/file23104/larry.utimensat.patch.r1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12904>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to