~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: John Arbash Meinel
  • Date: 2009-06-04 16:50:33 UTC
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: john@arbash-meinel.com-20090604165033-bfdo0lyf4yt4vjcz
We don't need a base Coder class, because Decoder._update_tail is different than Encoder._update_tail.
(one adds, one subtracts from self.size).
So we now have 2 versions of the macro, and the test suite stops crashing... :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012 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:
95
91
            return self._st_size
96
92
 
97
93
    # os.stat always returns 0, so we hard code it here
98
 
    property st_dev:
99
 
        def __get__(self):
100
 
            return 0
101
 
    property st_ino:
102
 
        def __get__(self):
103
 
            return 0
104
 
    # st_uid and st_gid required for some external tools like bzr-git & dulwich
105
 
    property st_uid:
106
 
        def __get__(self):
107
 
            return 0
108
 
    property st_gid:
109
 
        def __get__(self):
110
 
            return 0
 
94
    cdef readonly int st_dev
 
95
    cdef readonly int st_ino
111
96
 
112
97
    def __repr__(self):
113
98
        """Repr is the same as a Stat object.
124
109
                                 wcslen(data.cFileName))
125
110
 
126
111
 
127
 
cdef int _get_mode_bits(WIN32_FIND_DATAW *data): # cannot_raise
 
112
cdef int _get_mode_bits(WIN32_FIND_DATAW *data):
128
113
    cdef int mode_bits
129
114
 
130
115
    mode_bits = 0100666 # writeable file, the most common
136
121
    return mode_bits
137
122
 
138
123
 
139
 
cdef __int64 _get_size(WIN32_FIND_DATAW *data): # cannot_raise
 
124
cdef __int64 _get_size(WIN32_FIND_DATAW *data):
140
125
    # Pyrex casts a DWORD into a PyLong anyway, so it is safe to do << 32
141
126
    # on a DWORD
142
127
    return ((<__int64>data.nFileSizeHigh) << 32) + data.nFileSizeLow
143
128
 
144
129
 
145
 
cdef double _ftime_to_timestamp(FILETIME *ft): # cannot_raise
 
130
cdef double _ftime_to_timestamp(FILETIME *ft):
146
131
    """Convert from a FILETIME struct into a floating point timestamp.
147
132
 
148
133
    The fields of a FILETIME structure are the hi and lo part
162
147
    return (val * 1.0e-7) - 11644473600.0
163
148
 
164
149
 
165
 
cdef int _should_skip(WIN32_FIND_DATAW *data): # cannot_raise
 
150
cdef int _should_skip(WIN32_FIND_DATAW *data):
166
151
    """Is this '.' or '..' so we should skip it?"""
167
152
    if (data.cFileName[0] != c'.'):
168
153
        return 0
185
170
 
186
171
    def top_prefix_to_starting_dir(self, top, prefix=""):
187
172
        """See DirReader.top_prefix_to_starting_dir."""
188
 
        global osutils
189
 
        if osutils is None:
190
 
            from bzrlib import osutils
191
173
        return (osutils.safe_utf8(prefix), None, None, None,
192
174
                osutils.safe_unicode(top))
193
175
 
206
188
        statvalue.st_mtime = _ftime_to_timestamp(&data.ftLastWriteTime)
207
189
        statvalue.st_atime = _ftime_to_timestamp(&data.ftLastAccessTime)
208
190
        statvalue._st_size = _get_size(data)
 
191
        statvalue.st_ino = 0
 
192
        statvalue.st_dev = 0
209
193
        return statvalue
210
194
 
211
195
    def read_dir(self, prefix, top):
266
250
                #       earlier Exception, so for now, I'm ignoring this
267
251
        dirblock.sort(key=operator.itemgetter(1))
268
252
        return dirblock
269
 
 
270
 
 
271
 
def lstat(path):
272
 
    """Equivalent to os.lstat, except match Win32ReadDir._get_stat_value.
273
 
    """
274
 
    return wrap_stat(os.lstat(path))
275
 
 
276
 
 
277
 
def fstat(fd):
278
 
    """Like os.fstat, except match Win32ReadDir._get_stat_value
279
 
 
280
 
    :seealso: wrap_stat
281
 
    """
282
 
    return wrap_stat(os.fstat(fd))
283
 
 
284
 
 
285
 
def wrap_stat(st):
286
 
    """Return a _Win32Stat object, based on the given stat result.
287
 
 
288
 
    On Windows, os.fstat(open(fname).fileno()) != os.lstat(fname). This is
289
 
    generally because os.lstat and os.fstat differ in what they put into st_ino
290
 
    and st_dev. What gets set where seems to also be dependent on the python
291
 
    version. So we always set it to 0 to avoid worrying about it.
292
 
    """
293
 
    cdef _Win32Stat statvalue
294
 
    statvalue = _Win32Stat()
295
 
    statvalue.st_mode = st.st_mode
296
 
    statvalue.st_ctime = st.st_ctime
297
 
    statvalue.st_mtime = st.st_mtime
298
 
    statvalue.st_atime = st.st_atime
299
 
    statvalue._st_size = st.st_size
300
 
    return statvalue