~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 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
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.
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