]> granicus.if.org Git - python/commitdiff
Revert utime(..., None) strategy (it has too poor resolution under Windows) and resto...
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 23 Nov 2013 01:11:02 +0000 (02:11 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 23 Nov 2013 01:11:02 +0000 (02:11 +0100)
(issue #19715)

Lib/pathlib.py
Lib/test/test_pathlib.py

index e73eca7ec9f0e6124f9a93f0d2cbe92d93bbb91a..06cbae5ce3d1f8c4ac7db76742078329239355b2 100644 (file)
@@ -6,6 +6,7 @@ import os
 import posixpath
 import re
 import sys
+import time
 import weakref
 try:
     import threading
@@ -1075,8 +1076,9 @@ class Path(PurePath):
             # First try to bump modification time
             # Implementation note: GNU touch uses the UTIME_NOW option of
             # the utimensat() / futimens() functions.
+            t = time.time()
             try:
-                self._accessor.utime(self, None)
+                self._accessor.utime(self, (t, t))
             except OSError:
                 # Avoid exception chaining
                 pass
index 049e12d9cc5e100a6979d2345763a63522e0b9c0..6663ffa2833e02e420dd1c5eec458df897154b60 100755 (executable)
@@ -1391,8 +1391,11 @@ class _BasePathTest(object):
         # The file mtime should be refreshed by calling touch() again
         p.touch()
         st = p.stat()
-        self.assertGreaterEqual(st.st_mtime_ns, old_mtime_ns)
-        self.assertGreaterEqual(st.st_mtime, old_mtime)
+        # Issue #19715: there can be an inconsistency under Windows between
+        # the timestamp rounding when creating a file, and the timestamp
+        # rounding done when calling utime().  `delta` makes up for this.
+        delta = 1e-6 if os.name == 'nt' else 0
+        self.assertGreaterEqual(st.st_mtime, old_mtime - delta)
         # Now with exist_ok=False
         p = P / 'newfileB'
         self.assertFalse(p.exists())