Message143563
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. |
|
Date |
User |
Action |
Args |
2011-09-05 21:08:02 | larry | set | recipients:
+ larry |
2011-09-05 21:08:02 | larry | set | messageid: <1315256882.76.0.179568612134.issue12904@psf.upfronthosting.co.za> |
2011-09-05 21:08:02 | larry | link | issue12904 messages |
2011-09-05 21:08:01 | larry | create | |
|