/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/_readdir_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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
80
78
 
81
79
cdef extern from 'Python.h':
82
80
    int PyErr_CheckSignals() except -1
83
 
    char * PyString_AS_STRING(object)
 
81
    char * PyBytes_AS_STRING(object)
84
82
    ctypedef struct PyObject:
85
83
        pass
86
 
    Py_ssize_t PyString_Size(object s)
 
84
    Py_ssize_t PyBytes_Size(object s)
87
85
    object PyList_GetItem(object lst, Py_ssize_t index)
88
86
    void *PyList_GetItem_object_void "PyList_GET_ITEM" (object lst, int index)
89
87
    int PyList_Append(object lst, object item) except -1
92
90
    int PyTuple_SetItem_obj "PyTuple_SetItem" (void *, Py_ssize_t pos, PyObject * item) except -1
93
91
    void Py_INCREF(object o)
94
92
    void Py_DECREF(object o)
95
 
    void PyString_Concat(PyObject **string, object newpart)
 
93
    void PyBytes_Concat(PyObject **string, object newpart)
96
94
 
97
95
 
98
96
cdef extern from 'dirent.h':
220
218
        cdef object name
221
219
        cdef PyObject * new_val_obj
222
220
 
223
 
        if PyString_Size(prefix):
224
 
            relprefix = prefix + '/'
 
221
        if PyBytes_Size(prefix):
 
222
            relprefix = prefix + b'/'
225
223
        else:
226
 
            relprefix = ''
227
 
        top_slash = top + '/'
 
224
            relprefix = b''
 
225
        top_slash = top + b'/'
228
226
 
229
227
        # read_dir supplies in should-stat order.
230
228
        # for _, name in sorted(_listdir(top)):
240
238
            # direct concat - faster than operator +.
241
239
            new_val_obj = <PyObject *>relprefix
242
240
            Py_INCREF(relprefix)
243
 
            PyString_Concat(&new_val_obj, name)
 
241
            PyBytes_Concat(&new_val_obj, name)
244
242
            if NULL == new_val_obj:
245
 
                # PyString_Concat will have setup an exception, but how to get
 
243
                # PyBytes_Concat will have setup an exception, but how to get
246
244
                # at it?
247
245
                raise Exception("failed to strcat")
248
246
            PyTuple_SetItem_obj(atuple, 0, new_val_obj)
256
254
            # direct concat - faster than operator +.
257
255
            new_val_obj = <PyObject *>top_slash
258
256
            Py_INCREF(top_slash)
259
 
            PyString_Concat(&new_val_obj, name)
 
257
            PyBytes_Concat(&new_val_obj, name)
260
258
            if NULL == new_val_obj:
261
 
                # PyString_Concat will have setup an exception, but how to get
 
259
                # PyBytes_Concat will have setup an exception, but how to get
262
260
                # at it?
263
261
                raise Exception("failed to strcat")
264
262
            PyTuple_SetItem_obj(atuple, 4, new_val_obj)
292
290
 
293
291
    # Avoid chdir('') because it causes problems on Sun OS, and avoid this if
294
292
    # staying in .
295
 
    if path != "" and path != '.':
 
293
    if path != b"" and path != b'.':
296
294
        # we change into the requested directory before reading, and back at the
297
295
        # end, because that turns out to make the stat calls measurably faster than
298
296
        # passing full paths every time.
308
306
        orig_dir_fd = -1
309
307
 
310
308
    try:
311
 
        the_dir = opendir(".")
 
309
        the_dir = opendir(b".")
312
310
        if NULL == the_dir:
313
311
            raise_os_error(errno, "opendir: ", path)
314
312
        try:
346
344
                    if stat_result != 0:
347
345
                        if errno != ENOENT:
348
346
                            raise_os_error(errno, "lstat: ",
349
 
                                path + "/" + entry.d_name)
 
347
                                path + b"/" + entry.d_name)
350
348
                        else:
351
349
                            # the file seems to have disappeared after being
352
350
                            # seen by readdir - perhaps a transient temporary