/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_walkdirs_win32.pyx

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

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
16
16
 
17
17
"""Helper functions for Walkdirs on win32."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
 
20
22
cdef extern from "python-compat.h":
21
23
    struct _HANDLE:
69
71
 
70
72
 
71
73
import operator
 
74
import os
72
75
import stat
73
76
 
74
 
from bzrlib import osutils, _readdir_py
 
77
from . import _readdir_py
 
78
 
 
79
cdef object osutils
 
80
osutils = None
75
81
 
76
82
 
77
83
cdef class _Win32Stat:
91
97
            return self._st_size
92
98
 
93
99
    # os.stat always returns 0, so we hard code it here
94
 
    cdef readonly int st_dev
95
 
    cdef readonly int st_ino
 
100
    property st_dev:
 
101
        def __get__(self):
 
102
            return 0
 
103
    property st_ino:
 
104
        def __get__(self):
 
105
            return 0
 
106
    # st_uid and st_gid required for some external tools like bzr-git & dulwich
 
107
    property st_uid:
 
108
        def __get__(self):
 
109
            return 0
 
110
    property st_gid:
 
111
        def __get__(self):
 
112
            return 0
96
113
 
97
114
    def __repr__(self):
98
115
        """Repr is the same as a Stat object.
170
187
 
171
188
    def top_prefix_to_starting_dir(self, top, prefix=""):
172
189
        """See DirReader.top_prefix_to_starting_dir."""
 
190
        global osutils
 
191
        if osutils is None:
 
192
            from . import osutils
173
193
        return (osutils.safe_utf8(prefix), None, None, None,
174
194
                osutils.safe_unicode(top))
175
195
 
188
208
        statvalue.st_mtime = _ftime_to_timestamp(&data.ftLastWriteTime)
189
209
        statvalue.st_atime = _ftime_to_timestamp(&data.ftLastAccessTime)
190
210
        statvalue._st_size = _get_size(data)
191
 
        statvalue.st_ino = 0
192
 
        statvalue.st_dev = 0
193
211
        return statvalue
194
212
 
195
213
    def read_dir(self, prefix, top):
250
268
                #       earlier Exception, so for now, I'm ignoring this
251
269
        dirblock.sort(key=operator.itemgetter(1))
252
270
        return dirblock
 
271
 
 
272
 
 
273
def lstat(path):
 
274
    """Equivalent to os.lstat, except match Win32ReadDir._get_stat_value.
 
275
    """
 
276
    return wrap_stat(os.lstat(path))
 
277
 
 
278
 
 
279
def fstat(fd):
 
280
    """Like os.fstat, except match Win32ReadDir._get_stat_value
 
281
 
 
282
    :seealso: wrap_stat
 
283
    """
 
284
    return wrap_stat(os.fstat(fd))
 
285
 
 
286
 
 
287
def wrap_stat(st):
 
288
    """Return a _Win32Stat object, based on the given stat result.
 
289
 
 
290
    On Windows, os.fstat(open(fname).fileno()) != os.lstat(fname). This is
 
291
    generally because os.lstat and os.fstat differ in what they put into st_ino
 
292
    and st_dev. What gets set where seems to also be dependent on the python
 
293
    version. So we always set it to 0 to avoid worrying about it.
 
294
    """
 
295
    cdef _Win32Stat statvalue
 
296
    statvalue = _Win32Stat()
 
297
    statvalue.st_mode = st.st_mode
 
298
    statvalue.st_ctime = st.st_ctime
 
299
    statvalue.st_mtime = st.st_mtime
 
300
    statvalue.st_atime = st.st_atime
 
301
    statvalue._st_size = st.st_size
 
302
    return statvalue