/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: John Arbash Meinel
  • Date: 2010-01-05 21:15:22 UTC
  • mto: (4934.1.9 2.1.0rc1-set-mtime)
  • mto: This revision was merged to the branch mainline in revision 4940.
  • Revision ID: john@arbash-meinel.com-20100105211522-s3vpbckrs9uvt11u
Move the functionality into osutils / extensions.

Aaron pointed out the functions should be on DiskTreeTransform not
spread some to TreeTransform.

Also, instead of using ctypes, we now just write our own function
in the win32 extension module. Which seems to work just fine.
And osutils.fset_mtime() is a thunk into that functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    # Wide character functions
60
60
    DWORD wcslen(WCHAR *)
61
61
 
 
62
    ctypedef struct LARGE_INTEGER:
 
63
        DWORD LowPart
 
64
        DWORD HighPart
 
65
 
 
66
    # TODO: Why does the win32 api use LARGE_INTEGER for this structure, but
 
67
    #       FILETIME for the return from FindFirstFileW
 
68
    ctypedef struct FILE_BASIC_INFO:
 
69
         LARGE_INTEGER CreationTime
 
70
         LARGE_INTEGER LastAccessTime
 
71
         LARGE_INTEGER LastWriteTime
 
72
         LARGE_INTEGER ChangeTime
 
73
         DWORD FileAttributes
 
74
 
 
75
    ctypedef enum FILE_INFO_BY_HANDLE_CLASS:
 
76
        FileBasicInfo
 
77
 
 
78
    int GetFileInformationByHandleEx(
 
79
        HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS type,
 
80
        void* fileInformationBuffer, DWORD bufSize)
 
81
    int SetFileInformationByHandle(
 
82
        HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS type,
 
83
        void* fileInformationBuffer, DWORD bufSize)
 
84
 
 
85
    long _get_osfhandle(int)
 
86
 
62
87
 
63
88
cdef extern from "Python.h":
64
89
    WCHAR *PyUnicode_AS_UNICODE(object)
68
93
    object PyUnicode_AsUTF8String(object)
69
94
 
70
95
 
 
96
import msvcrt
71
97
import operator
72
98
import stat
73
99
 
147
173
    return (val * 1.0e-7) - 11644473600.0
148
174
 
149
175
 
 
176
cdef FILETIME _timestamp_to_ftime(double timestamp):
 
177
    """Convert a time-since-epoch to a FILETIME."""
 
178
    cdef __int64 val
 
179
    cdef FILETIME result
 
180
 
 
181
    val = <__int64>((timestamp + 11644473600.0) * 1.0e7)
 
182
    result.dwHighDateTime = val >> 32
 
183
    result.dwLowDateTime = val & 0xFFFFFFFF
 
184
    return result
 
185
 
 
186
 
150
187
cdef int _should_skip(WIN32_FIND_DATAW *data):
151
188
    """Is this '.' or '..' so we should skip it?"""
152
189
    if (data.cFileName[0] != c'.'):
250
287
                #       earlier Exception, so for now, I'm ignoring this
251
288
        dirblock.sort(key=operator.itemgetter(1))
252
289
        return dirblock
 
290
 
 
291
 
 
292
def fset_mtime(fileno, mtime):
 
293
    """See osutils.fset_mtime."""
 
294
    cdef HANDLE the_handle
 
295
    cdef FILE_BASIC_INFO bi
 
296
    cdef FILETIME ft
 
297
    cdef int retval
 
298
 
 
299
    ft = _timestamp_to_ftime(mtime)
 
300
    the_handle = <HANDLE>(_get_osfhandle(fileno))
 
301
    if the_handle == <HANDLE>(-1):
 
302
        raise OSError('Invalid fileno') # IOError?
 
303
    retval = GetFileInformationByHandleEx(the_handle, FileBasicInfo,
 
304
                                          &bi, sizeof(FILE_BASIC_INFO))
 
305
    if retval != 1:
 
306
        raise OSError('Failed to GetFileInformationByHandleEx')
 
307
    bi.LastWriteTime.LowPart = ft.dwLowDateTime
 
308
    bi.LastWriteTime.HighPart = ft.dwHighDateTime
 
309
    retval = SetFileInformationByHandle(the_handle, FileBasicInfo,
 
310
                                        &bi, sizeof(FILE_BASIC_INFO))
 
311
    if retval != 1:
 
312
        raise OSError('Failed to SetFileInformationByHandle')