/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: John Arbash Meinel
  • Date: 2009-06-12 18:05:15 UTC
  • mto: (4371.4.5 vila-better-heads)
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090612180515-t0cwbjsnve094oik
Add a failing test for handling nodes that are in the same linear chain.

It fails because the ancestry skipping causes us to miss the fact that the two nodes
are actually directly related. We could check at the beginning, as the 
code used to do, but I think that will be incomplete for the more-than-two
heads cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2008, 2009 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
78
78
 
79
79
 
80
80
cdef extern from 'Python.h':
81
 
    int PyErr_CheckSignals() except -1
82
81
    char * PyString_AS_STRING(object)
83
82
    ctypedef int Py_ssize_t # Required for older pyrex versions
84
83
    ctypedef struct PyObject:
156
155
        (mode, ino, dev, nlink, uid, gid, size, None(atime), mtime, ctime)
157
156
        """
158
157
        return repr((self.st_mode, 0, 0, 0, 0, 0, self.st_size, None,
159
 
                     self.st_mtime, self.st_ctime))
 
158
                     self._mtime, self._ctime))
160
159
 
161
160
 
162
161
from bzrlib import osutils
272
271
        return result
273
272
 
274
273
 
275
 
cdef raise_os_error(int errnum, char *msg_prefix, path):
276
 
    if errnum == EINTR:
277
 
        PyErr_CheckSignals()
278
 
    raise OSError(errnum, msg_prefix + strerror(errnum), path)
279
 
 
280
 
 
281
274
cdef _read_dir(path):
282
275
    """Like os.listdir, this reads the contents of a directory.
283
276
 
305
298
        # passing full paths every time.
306
299
        orig_dir_fd = open(".", O_RDONLY, 0)
307
300
        if orig_dir_fd == -1:
308
 
            raise_os_error(errno, "open: ", ".")
 
301
            raise OSError(errno, "open: " + strerror(errno), ".")
309
302
        if -1 == chdir(path):
310
 
            raise_os_error(errno, "chdir: ", path)
 
303
            raise OSError(errno, "chdir: " + strerror(errno), path)
311
304
    else:
312
305
        orig_dir_fd = -1
313
306
 
314
307
    try:
315
308
        the_dir = opendir(".")
316
309
        if NULL == the_dir:
317
 
            raise_os_error(errno, "opendir: ", path)
 
310
            raise OSError(errno, "opendir: " + strerror(errno), path)
318
311
        try:
319
312
            result = []
320
313
            entry = &sentinel
326
319
                    errno = 0
327
320
                    entry = readdir(the_dir)
328
321
                    if entry == NULL and (errno == EAGAIN or errno == EINTR):
329
 
                        if errno == EINTR:
330
 
                            PyErr_CheckSignals()
331
322
                        # try again
332
323
                        continue
333
324
                    else:
339
330
                        # we consider ENOTDIR to be 'no error'.
340
331
                        continue
341
332
                    else:
342
 
                        raise_os_error(errno, "readdir: ", path)
 
333
                        raise OSError(errno, "readdir: " + strerror(errno), path)
343
334
                name = entry.d_name
344
335
                if not (name[0] == c"." and (
345
336
                    (name[1] == 0) or 
349
340
                    stat_result = lstat(entry.d_name, &statvalue._st)
350
341
                    if stat_result != 0:
351
342
                        if errno != ENOENT:
352
 
                            raise_os_error(errno, "lstat: ",
 
343
                            raise OSError(errno, "lstat: " + strerror(errno),
353
344
                                path + "/" + entry.d_name)
354
345
                        else:
355
 
                            # the file seems to have disappeared after being
356
 
                            # seen by readdir - perhaps a transient temporary
357
 
                            # file.  there's no point returning it.
358
 
                            continue
 
346
                            kind = _missing
 
347
                            statvalue = None
359
348
                    # We append a 5-tuple that can be modified in-place by the C
360
349
                    # api:
361
350
                    # inode to sort on (to replace with top_path)
367
356
                        statvalue, None))
368
357
        finally:
369
358
            if -1 == closedir(the_dir):
370
 
                raise_os_error(errno, "closedir: ", path)
 
359
                raise OSError(errno, "closedir: " + strerror(errno), path)
371
360
    finally:
372
361
        if -1 != orig_dir_fd:
373
362
            failed = False
375
364
                # try to close the original directory anyhow
376
365
                failed = True
377
366
            if -1 == close(orig_dir_fd) or failed:
378
 
                raise_os_error(errno, "return to orig_dir: ", "")
 
367
                raise OSError(errno, "return to orig_dir: " + strerror(errno))
379
368
 
380
369
    return result
381
370