]> granicus.if.org Git - python/commitdiff
Bug #1565150: Fix subsecond processing for os.utime on Windows.
authorMartin v. Löwis <martin@v.loewis.de>
Mon, 9 Oct 2006 20:44:25 +0000 (20:44 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Mon, 9 Oct 2006 20:44:25 +0000 (20:44 +0000)
Lib/test/test_os.py
Misc/NEWS
Modules/posixmodule.c

index 9497777218cbccf3909d9daba376b75aa2dbf062..984484c4c36ec24828c361dd904bb7567dc4c045 100644 (file)
@@ -223,6 +223,14 @@ class StatAttributeTests(unittest.TestCase):
         except TypeError:
             pass
 
+    # Restrict test to Win32, since there is no guarantee other
+    # systems support centiseconds
+    if sys.platform == 'win32':
+        def test_1565150(self):
+            t1 = 1159195039.25
+            os.utime(self.fname, (t1, t1))
+            self.assertEquals(os.stat(self.fname).st_mtime, t1)
+
 from test import mapping_tests
 
 class EnvironTests(mapping_tests.BasicTestMappingProtocol):
index 0b9aade4f4f7ca81694c35a57df8b2acecac2e38..760dc1ef4b948a044add93f7e5e9291b0e712391 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -75,6 +75,8 @@ Core and builtins
 Library
 -------
 
+- Bug #1565150: Fix subsecond processing for os.utime on Windows.
+
 - Support for MSVC 8 was added to bdist_wininst.
 
 - Bug #1446043: correctly raise a LookupError if an encoding name given
index 45ea9886ebf40ca151b68e8f16e53c471ee0c41b..93d030017d10f9900ccd66906ba603c9732c027c 100644 (file)
@@ -792,7 +792,7 @@ time_t_to_FILE_TIME(int time_in, int nsec_in, FILETIME *out_ptr)
        /* XXX endianness */
        __int64 out;
        out = time_in + secs_between_epochs;
-       out = out * 10000000 + nsec_in;
+       out = out * 10000000 + nsec_in / 100;
        memcpy(out_ptr, &out, sizeof(out));
 }
 
@@ -2501,11 +2501,11 @@ posix_utime(PyObject *self, PyObject *args)
                if (extract_time(PyTuple_GET_ITEM(arg, 0),
                                 &atimesec, &ausec) == -1)
                        goto done;
-               time_t_to_FILE_TIME(atimesec, ausec, &atime);
+               time_t_to_FILE_TIME(atimesec, 1000*ausec, &atime);
                if (extract_time(PyTuple_GET_ITEM(arg, 1),
                                 &mtimesec, &musec) == -1)
                        goto done;
-               time_t_to_FILE_TIME(mtimesec, musec, &mtime);
+               time_t_to_FILE_TIME(mtimesec, 1000*musec, &mtime);
        }
        if (!SetFileTime(hFile, NULL, &atime, &mtime)) {
                /* Avoid putting the file name into the error here,