/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/_readdir_pyx.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:
16
16
 
17
17
"""Wrapper for readdir which returns files ordered by inode."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
 
22
20
import os
23
21
import sys
24
22
 
 
23
#python2.4 support
25
24
cdef extern from "python-compat.h":
26
25
    pass
27
26
 
80
79
 
81
80
cdef extern from 'Python.h':
82
81
    int PyErr_CheckSignals() except -1
83
 
    char * PyBytes_AS_STRING(object)
 
82
    char * PyString_AS_STRING(object)
 
83
    ctypedef int Py_ssize_t # Required for older pyrex versions
84
84
    ctypedef struct PyObject:
85
85
        pass
86
 
    Py_ssize_t PyBytes_Size(object s)
 
86
    Py_ssize_t PyString_Size(object s)
87
87
    object PyList_GetItem(object lst, Py_ssize_t index)
88
88
    void *PyList_GetItem_object_void "PyList_GET_ITEM" (object lst, int index)
89
89
    int PyList_Append(object lst, object item) except -1
92
92
    int PyTuple_SetItem_obj "PyTuple_SetItem" (void *, Py_ssize_t pos, PyObject * item) except -1
93
93
    void Py_INCREF(object o)
94
94
    void Py_DECREF(object o)
95
 
    void PyBytes_Concat(PyObject **string, object newpart)
 
95
    void PyString_Concat(PyObject **string, object newpart)
96
96
 
97
97
 
98
98
cdef extern from 'dirent.h':
166
166
                     self.st_mtime, self.st_ctime))
167
167
 
168
168
 
169
 
from . import osutils
 
169
from bzrlib import osutils
170
170
 
171
171
cdef object _safe_utf8
172
172
_safe_utf8 = osutils.safe_utf8
220
220
        cdef object name
221
221
        cdef PyObject * new_val_obj
222
222
 
223
 
        if PyBytes_Size(prefix):
224
 
            relprefix = prefix + b'/'
 
223
        if PyString_Size(prefix):
 
224
            relprefix = prefix + '/'
225
225
        else:
226
 
            relprefix = b''
227
 
        top_slash = top + b'/'
 
226
            relprefix = ''
 
227
        top_slash = top + '/'
228
228
 
229
229
        # read_dir supplies in should-stat order.
230
230
        # for _, name in sorted(_listdir(top)):
240
240
            # direct concat - faster than operator +.
241
241
            new_val_obj = <PyObject *>relprefix
242
242
            Py_INCREF(relprefix)
243
 
            PyBytes_Concat(&new_val_obj, name)
 
243
            PyString_Concat(&new_val_obj, name)
244
244
            if NULL == new_val_obj:
245
 
                # PyBytes_Concat will have setup an exception, but how to get
 
245
                # PyString_Concat will have setup an exception, but how to get
246
246
                # at it?
247
247
                raise Exception("failed to strcat")
248
248
            PyTuple_SetItem_obj(atuple, 0, new_val_obj)
256
256
            # direct concat - faster than operator +.
257
257
            new_val_obj = <PyObject *>top_slash
258
258
            Py_INCREF(top_slash)
259
 
            PyBytes_Concat(&new_val_obj, name)
 
259
            PyString_Concat(&new_val_obj, name)
260
260
            if NULL == new_val_obj:
261
 
                # PyBytes_Concat will have setup an exception, but how to get
 
261
                # PyString_Concat will have setup an exception, but how to get
262
262
                # at it?
263
263
                raise Exception("failed to strcat")
264
264
            PyTuple_SetItem_obj(atuple, 4, new_val_obj)
292
292
 
293
293
    # Avoid chdir('') because it causes problems on Sun OS, and avoid this if
294
294
    # staying in .
295
 
    if path != b"" and path != b'.':
 
295
    if path != "" and path != '.':
296
296
        # we change into the requested directory before reading, and back at the
297
297
        # end, because that turns out to make the stat calls measurably faster than
298
298
        # passing full paths every time.
308
308
        orig_dir_fd = -1
309
309
 
310
310
    try:
311
 
        the_dir = opendir(b".")
 
311
        the_dir = opendir(".")
312
312
        if NULL == the_dir:
313
313
            raise_os_error(errno, "opendir: ", path)
314
314
        try:
346
346
                    if stat_result != 0:
347
347
                        if errno != ENOENT:
348
348
                            raise_os_error(errno, "lstat: ",
349
 
                                path + b"/" + entry.d_name)
 
349
                                path + "/" + entry.d_name)
350
350
                        else:
351
351
                            # the file seems to have disappeared after being
352
352
                            # seen by readdir - perhaps a transient temporary