~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: Aaron Bentley
  • Date: 2009-06-19 21:16:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4481.
  • Revision ID: aaron@aaronbentley.com-20090619211631-4fnkv2uui98xj7ux
Provide control over switch and shelver messaging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
69
69
 
70
70
 
71
71
import operator
72
 
import os
73
72
import stat
74
73
 
75
 
from bzrlib import _readdir_py
76
 
 
77
 
cdef object osutils
78
 
osutils = None
 
74
from bzrlib import osutils, _readdir_py
79
75
 
80
76
 
81
77
cdef class _Win32Stat:
113
109
                                 wcslen(data.cFileName))
114
110
 
115
111
 
116
 
cdef int _get_mode_bits(WIN32_FIND_DATAW *data): # cannot_raise
 
112
cdef int _get_mode_bits(WIN32_FIND_DATAW *data):
117
113
    cdef int mode_bits
118
114
 
119
115
    mode_bits = 0100666 # writeable file, the most common
125
121
    return mode_bits
126
122
 
127
123
 
128
 
cdef __int64 _get_size(WIN32_FIND_DATAW *data): # cannot_raise
 
124
cdef __int64 _get_size(WIN32_FIND_DATAW *data):
129
125
    # Pyrex casts a DWORD into a PyLong anyway, so it is safe to do << 32
130
126
    # on a DWORD
131
127
    return ((<__int64>data.nFileSizeHigh) << 32) + data.nFileSizeLow
132
128
 
133
129
 
134
 
cdef double _ftime_to_timestamp(FILETIME *ft): # cannot_raise
 
130
cdef double _ftime_to_timestamp(FILETIME *ft):
135
131
    """Convert from a FILETIME struct into a floating point timestamp.
136
132
 
137
133
    The fields of a FILETIME structure are the hi and lo part
151
147
    return (val * 1.0e-7) - 11644473600.0
152
148
 
153
149
 
154
 
cdef int _should_skip(WIN32_FIND_DATAW *data): # cannot_raise
 
150
cdef int _should_skip(WIN32_FIND_DATAW *data):
155
151
    """Is this '.' or '..' so we should skip it?"""
156
152
    if (data.cFileName[0] != c'.'):
157
153
        return 0
174
170
 
175
171
    def top_prefix_to_starting_dir(self, top, prefix=""):
176
172
        """See DirReader.top_prefix_to_starting_dir."""
177
 
        global osutils
178
 
        if osutils is None:
179
 
            from bzrlib import osutils
180
173
        return (osutils.safe_utf8(prefix), None, None, None,
181
174
                osutils.safe_unicode(top))
182
175
 
257
250
                #       earlier Exception, so for now, I'm ignoring this
258
251
        dirblock.sort(key=operator.itemgetter(1))
259
252
        return dirblock
260
 
 
261
 
 
262
 
def lstat(path):
263
 
    """Equivalent to os.lstat, except match Win32ReadDir._get_stat_value.
264
 
    """
265
 
    return wrap_stat(os.lstat(path))
266
 
 
267
 
 
268
 
def fstat(fd):
269
 
    """Like os.fstat, except match Win32ReadDir._get_stat_value
270
 
 
271
 
    :seealso: wrap_stat
272
 
    """
273
 
    return wrap_stat(os.fstat(fd))
274
 
 
275
 
 
276
 
def wrap_stat(st):
277
 
    """Return a _Win32Stat object, based on the given stat result.
278
 
 
279
 
    On Windows, os.fstat(open(fname).fileno()) != os.lstat(fname). This is
280
 
    generally because os.lstat and os.fstat differ in what they put into st_ino
281
 
    and st_dev. What gets set where seems to also be dependent on the python
282
 
    version. So we always set it to 0 to avoid worrying about it.
283
 
    """
284
 
    cdef _Win32Stat statvalue
285
 
    statvalue = _Win32Stat()
286
 
    statvalue.st_mode = st.st_mode
287
 
    statvalue.st_ctime = st.st_ctime
288
 
    statvalue.st_mtime = st.st_mtime
289
 
    statvalue.st_atime = st.st_atime
290
 
    statvalue._st_size = st.st_size
291
 
    statvalue.st_ino = 0
292
 
    statvalue.st_dev = 0
293
 
    return statvalue