~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008-2011 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Helper functions for Walkdirs on win32."""
18
18
 
69
69
 
70
70
 
71
71
import operator
 
72
import os
72
73
import stat
73
74
 
74
 
from bzrlib import osutils, _readdir_py
 
75
from bzrlib import _readdir_py
 
76
 
 
77
cdef object osutils
 
78
osutils = None
75
79
 
76
80
 
77
81
cdef class _Win32Stat:
81
85
    cdef readonly double st_ctime
82
86
    cdef readonly double st_mtime
83
87
    cdef readonly double st_atime
84
 
    cdef readonly __int64 st_size
 
88
    # We can't just declare this as 'readonly' because python2.4 doesn't define
 
89
    # T_LONGLONG as a structure member. So instead we just use a property that
 
90
    # will convert it correctly anyway.
 
91
    cdef __int64 _st_size
 
92
 
 
93
    property st_size:
 
94
        def __get__(self):
 
95
            return self._st_size
85
96
 
86
97
    # os.stat always returns 0, so we hard code it here
87
98
    cdef readonly int st_dev
102
113
                                 wcslen(data.cFileName))
103
114
 
104
115
 
105
 
cdef int _get_mode_bits(WIN32_FIND_DATAW *data):
 
116
cdef int _get_mode_bits(WIN32_FIND_DATAW *data): # cannot_raise
106
117
    cdef int mode_bits
107
118
 
108
119
    mode_bits = 0100666 # writeable file, the most common
114
125
    return mode_bits
115
126
 
116
127
 
117
 
cdef __int64 _get_size(WIN32_FIND_DATAW *data):
 
128
cdef __int64 _get_size(WIN32_FIND_DATAW *data): # cannot_raise
118
129
    # Pyrex casts a DWORD into a PyLong anyway, so it is safe to do << 32
119
130
    # on a DWORD
120
131
    return ((<__int64>data.nFileSizeHigh) << 32) + data.nFileSizeLow
121
132
 
122
133
 
123
 
cdef double _ftime_to_timestamp(FILETIME *ft):
 
134
cdef double _ftime_to_timestamp(FILETIME *ft): # cannot_raise
124
135
    """Convert from a FILETIME struct into a floating point timestamp.
125
136
 
126
137
    The fields of a FILETIME structure are the hi and lo part
140
151
    return (val * 1.0e-7) - 11644473600.0
141
152
 
142
153
 
143
 
cdef int _should_skip(WIN32_FIND_DATAW *data):
 
154
cdef int _should_skip(WIN32_FIND_DATAW *data): # cannot_raise
144
155
    """Is this '.' or '..' so we should skip it?"""
145
156
    if (data.cFileName[0] != c'.'):
146
157
        return 0
163
174
 
164
175
    def top_prefix_to_starting_dir(self, top, prefix=""):
165
176
        """See DirReader.top_prefix_to_starting_dir."""
 
177
        global osutils
 
178
        if osutils is None:
 
179
            from bzrlib import osutils
166
180
        return (osutils.safe_utf8(prefix), None, None, None,
167
181
                osutils.safe_unicode(top))
168
182
 
180
194
        statvalue.st_ctime = _ftime_to_timestamp(&data.ftCreationTime)
181
195
        statvalue.st_mtime = _ftime_to_timestamp(&data.ftLastWriteTime)
182
196
        statvalue.st_atime = _ftime_to_timestamp(&data.ftLastAccessTime)
183
 
        statvalue.st_size = _get_size(data)
 
197
        statvalue._st_size = _get_size(data)
184
198
        statvalue.st_ino = 0
185
199
        statvalue.st_dev = 0
186
200
        return statvalue
243
257
                #       earlier Exception, so for now, I'm ignoring this
244
258
        dirblock.sort(key=operator.itemgetter(1))
245
259
        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