~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: John Arbash Meinel
  • Date: 2010-01-06 22:17:10 UTC
  • mto: This revision was merged to the branch mainline in revision 4940.
  • Revision ID: john@arbash-meinel.com-20100106221710-3shwzqvrfne5mlyi
Revert all of the extension code.

Instead, just stick with os.utime. It is *much* simpler, and I couldn't
find a performance impact of not using it.
The one small difference is that you should call it after closing
the file, but that is reasonable to do anyway.

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
 
    int SetFileTime(
63
 
        HANDLE hFile, FILETIME *lpCreationTime, FILETIME *lpLastAccessTime,
64
 
        FILETIME *lpLastWriteTime)
65
 
 
66
 
    long _get_osfhandle(int)
67
 
 
68
62
 
69
63
cdef extern from "Python.h":
70
64
    WCHAR *PyUnicode_AS_UNICODE(object)
153
147
    return (val * 1.0e-7) - 11644473600.0
154
148
 
155
149
 
156
 
cdef FILETIME _timestamp_to_ftime(double timestamp):
157
 
    """Convert a time-since-epoch to a FILETIME."""
158
 
    cdef __int64 val
159
 
    cdef FILETIME result
160
 
 
161
 
    val = <__int64>((timestamp + 11644473600.0) * 1.0e7)
162
 
    result.dwHighDateTime = <DWORD>(val >> 32)
163
 
    result.dwLowDateTime = <DWORD>(val & 0xFFFFFFFF)
164
 
    return result
165
 
 
166
 
 
167
150
cdef int _should_skip(WIN32_FIND_DATAW *data):
168
151
    """Is this '.' or '..' so we should skip it?"""
169
152
    if (data.cFileName[0] != c'.'):
267
250
                #       earlier Exception, so for now, I'm ignoring this
268
251
        dirblock.sort(key=operator.itemgetter(1))
269
252
        return dirblock
270
 
 
271
 
 
272
 
def fset_mtime(f, mtime):
273
 
    """See osutils.fset_mtime."""
274
 
    cdef HANDLE the_handle
275
 
    cdef FILETIME ft
276
 
    cdef int retval
277
 
 
278
 
    ft = _timestamp_to_ftime(mtime)
279
 
    the_handle = <HANDLE>(_get_osfhandle(f.fileno()))
280
 
    if the_handle == <HANDLE>(-1):
281
 
        raise OSError('Invalid fileno') # IOError?
282
 
    retval = SetFileTime(the_handle, NULL, NULL, &ft)
283
 
    if retval == 0:
284
 
        raise WindowsError(GetLastError(), "Failed to set file modified time")