~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_walkdirs_win32.pyx

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 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
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:
170
174
 
171
175
    def top_prefix_to_starting_dir(self, top, prefix=""):
172
176
        """See DirReader.top_prefix_to_starting_dir."""
 
177
        global osutils
 
178
        if osutils is None:
 
179
            from bzrlib import osutils
173
180
        return (osutils.safe_utf8(prefix), None, None, None,
174
181
                osutils.safe_unicode(top))
175
182
 
250
257
                #       earlier Exception, so for now, I'm ignoring this
251
258
        dirblock.sort(key=operator.itemgetter(1))
252
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