/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 bzrlib/_walkdirs_win32.pyx

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 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
 
 
21
19
 
22
20
cdef extern from "python-compat.h":
23
21
    struct _HANDLE:
71
69
 
72
70
 
73
71
import operator
74
 
import os
75
72
import stat
76
73
 
77
 
from . import _readdir_py
78
 
 
79
 
cdef object osutils
80
 
osutils = None
 
74
from bzrlib import osutils, _readdir_py
81
75
 
82
76
 
83
77
cdef class _Win32Stat:
97
91
            return self._st_size
98
92
 
99
93
    # os.stat always returns 0, so we hard code it here
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
 
94
    cdef readonly int st_dev
 
95
    cdef readonly int st_ino
113
96
 
114
97
    def __repr__(self):
115
98
        """Repr is the same as a Stat object.
187
170
 
188
171
    def top_prefix_to_starting_dir(self, top, prefix=""):
189
172
        """See DirReader.top_prefix_to_starting_dir."""
190
 
        global osutils
191
 
        if osutils is None:
192
 
            from . import osutils
193
173
        return (osutils.safe_utf8(prefix), None, None, None,
194
174
                osutils.safe_unicode(top))
195
175
 
208
188
        statvalue.st_mtime = _ftime_to_timestamp(&data.ftLastWriteTime)
209
189
        statvalue.st_atime = _ftime_to_timestamp(&data.ftLastAccessTime)
210
190
        statvalue._st_size = _get_size(data)
 
191
        statvalue.st_ino = 0
 
192
        statvalue.st_dev = 0
211
193
        return statvalue
212
194
 
213
195
    def read_dir(self, prefix, top):
268
250
                #       earlier Exception, so for now, I'm ignoring this
269
251
        dirblock.sort(key=operator.itemgetter(1))
270
252
        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