/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: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
#
17
 
# cython: language_level=3
18
16
 
19
17
"""Wrapper for readdir which returns files ordered by inode."""
20
18
 
 
19
from __future__ import absolute_import
 
20
 
21
21
 
22
22
import os
23
23
import sys
80
80
 
81
81
cdef extern from 'Python.h':
82
82
    int PyErr_CheckSignals() except -1
83
 
    char * PyBytes_AS_STRING(object)
 
83
    char * PyString_AS_STRING(object)
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':
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