Rev 3510: Start exposing the times on the stat, this now seems to be a complete walkdirs implementation. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/win32_find_files

John Arbash Meinel john at arbash-meinel.com
Thu Jul 17 03:37:19 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/win32_find_files

------------------------------------------------------------
revno: 3510
revision-id: john at arbash-meinel.com-20080717023713-832g08rsq7emxh8f
parent: john at arbash-meinel.com-20080717022133-hcd78dqy2qn60drx
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: win32_find_files
timestamp: Wed 2008-07-16 21:37:13 -0500
message:
  Start exposing the times on the stat, this now seems to be a complete walkdirs implementation.
-------------- next part --------------
=== modified file 'bzrlib/_walkdirs_win32.pyx'
--- a/bzrlib/_walkdirs_win32.pyx	2008-07-16 23:29:29 +0000
+++ b/bzrlib/_walkdirs_win32.pyx	2008-07-17 02:37:13 +0000
@@ -18,17 +18,14 @@
 
 
 cdef extern from "_walkdirs_win32.h":
-    cdef struct FINDFILE:
-        int low
-        int high
-
     cdef struct _HANDLE:
         pass
     ctypedef _HANDLE *HANDLE
     ctypedef unsigned int DWORD
     ctypedef unsigned short WCHAR
     cdef struct _FILETIME:
-        pass
+        DWORD dwHighDateTime
+        DWORD dwLowDateTime
     ctypedef _FILETIME FILETIME
 
     cdef struct _WIN32_FIND_DATAW:
@@ -151,9 +148,9 @@
         statvalue = _Win32Stat()
         statvalue.st_mode = self._get_mode_bits(data)
         # TODO: Convert the filetimes
-        statvalue.st_ctime = 0
-        statvalue.st_atime = 0
-        statvalue.st_mtime = 0
+        statvalue.st_ctime = self._ftime_to_timestamp(&data.ftCreationTime)
+        statvalue.st_atime = self._ftime_to_timestamp(&data.ftLastAccessTime)
+        statvalue.st_mtime = self._ftime_to_timestamp(&data.ftLastWriteTime)
         statvalue.st_size = self._get_size(data)
         return statvalue
 
@@ -172,6 +169,20 @@
             return True
         return False
 
+    cdef double _ftime_to_timestamp(self, FILETIME *ft):
+        """Convert from a FILETIME struct into a floating point timestamp.
+
+        The fields of a FILETIME structure are the hi and lo part
+        of a 64-bit value expressed in 100 nanosecond units.
+        1e7 is one second in such units; 1e-7 the inverse.
+        429.4967296 is 2**32 / 1e7 or 2**32 * 1e-7.
+        It also uses the epoch 1601-01-01 rather than 1970-01-01
+        (taken from posixmodule.c)
+        """
+        # cdef double secs_between_epochs = 11644473600
+        return ((ft.dwHighDateTime * 429.4967296 + ft.dwLowDateTime * 1e-7)
+                - 11644473600.0)
+
     def _get_files_in(self, directory, relprefix):
         cdef WIN32_FIND_DATAW search_data
         cdef HANDLE hFindFile

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2008-07-17 02:21:33 +0000
+++ b/bzrlib/tests/test_osutils.py	2008-07-17 02:37:13 +0000
@@ -1054,9 +1054,9 @@
     def assertStatIsCorrect(self, path, win32stat):
         os_stat = os.stat(path)
         self.assertEqual(os_stat.st_size, win32stat.st_size)
-        self.assertEqual(os_stat.st_mtime, win32stat.st_mtime)
-        self.assertEqual(os_stat.st_ctime, win32stat.st_ctime)
-        self.assertEqual(os_stat.st_atime, win32stat.st_atime)
+        self.assertAlmostEqual(os_stat.st_mtime, win32stat.st_mtime, places=4)
+        self.assertAlmostEqual(os_stat.st_ctime, win32stat.st_ctime, places=4)
+        self.assertAlmostEqual(os_stat.st_atime, win32stat.st_atime, places=4)
         self.assertEqual(os_stat.st_dev, win32stat.st_dev)
         self.assertEqual(os_stat.st_ino, win32stat.st_ino)
         self.assertEqual(os_stat.st_mode, win32stat.st_mode)
@@ -1082,6 +1082,7 @@
         self.assertEqual((name0, name0, 'file'), entry[:3])
         self.assertEqual(u'./' + name0u, entry[4])
         self.assertStatIsCorrect(entry[4], entry[3])
+        self.assertNotEqual(entry[3].st_mtime, entry[3].st_ctime)
 
     def test__walkdirs_utf_win32_find_file_stat_directory(self):
         """make sure our Stat values are valid"""



More information about the bazaar-commits mailing list