~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

(vila) Empty arguments in EDITOR are now properly preserved. (Vincent
 Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008-2012 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:
91
95
            return self._st_size
92
96
 
93
97
    # os.stat always returns 0, so we hard code it here
94
 
    cdef readonly int st_dev
95
 
    cdef readonly int st_ino
 
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
96
111
 
97
112
    def __repr__(self):
98
113
        """Repr is the same as a Stat object.
109
124
                                 wcslen(data.cFileName))
110
125
 
111
126
 
112
 
cdef int _get_mode_bits(WIN32_FIND_DATAW *data):
 
127
cdef int _get_mode_bits(WIN32_FIND_DATAW *data): # cannot_raise
113
128
    cdef int mode_bits
114
129
 
115
130
    mode_bits = 0100666 # writeable file, the most common
121
136
    return mode_bits
122
137
 
123
138
 
124
 
cdef __int64 _get_size(WIN32_FIND_DATAW *data):
 
139
cdef __int64 _get_size(WIN32_FIND_DATAW *data): # cannot_raise
125
140
    # Pyrex casts a DWORD into a PyLong anyway, so it is safe to do << 32
126
141
    # on a DWORD
127
142
    return ((<__int64>data.nFileSizeHigh) << 32) + data.nFileSizeLow
128
143
 
129
144
 
130
 
cdef double _ftime_to_timestamp(FILETIME *ft):
 
145
cdef double _ftime_to_timestamp(FILETIME *ft): # cannot_raise
131
146
    """Convert from a FILETIME struct into a floating point timestamp.
132
147
 
133
148
    The fields of a FILETIME structure are the hi and lo part
147
162
    return (val * 1.0e-7) - 11644473600.0
148
163
 
149
164
 
150
 
cdef int _should_skip(WIN32_FIND_DATAW *data):
 
165
cdef int _should_skip(WIN32_FIND_DATAW *data): # cannot_raise
151
166
    """Is this '.' or '..' so we should skip it?"""
152
167
    if (data.cFileName[0] != c'.'):
153
168
        return 0
170
185
 
171
186
    def top_prefix_to_starting_dir(self, top, prefix=""):
172
187
        """See DirReader.top_prefix_to_starting_dir."""
 
188
        global osutils
 
189
        if osutils is None:
 
190
            from bzrlib import osutils
173
191
        return (osutils.safe_utf8(prefix), None, None, None,
174
192
                osutils.safe_unicode(top))
175
193
 
188
206
        statvalue.st_mtime = _ftime_to_timestamp(&data.ftLastWriteTime)
189
207
        statvalue.st_atime = _ftime_to_timestamp(&data.ftLastAccessTime)
190
208
        statvalue._st_size = _get_size(data)
191
 
        statvalue.st_ino = 0
192
 
        statvalue.st_dev = 0
193
209
        return statvalue
194
210
 
195
211
    def read_dir(self, prefix, top):
250
266
                #       earlier Exception, so for now, I'm ignoring this
251
267
        dirblock.sort(key=operator.itemgetter(1))
252
268
        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