~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_readdir_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2009-12-08 21:37:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4885.
  • Revision ID: john@arbash-meinel.com-20091208213736-vje7ublg3xzp1bs2
Now that we return files directly from the working tree
the windows 'attrib' test needed to be updated.
If we used the working tree for both old and new, then the test wasn't
really testing what we expected, which was that the newly generated
content was readable.

But using basis_tree gets us that. Also, test that the content is
properly marked as readonly, and that we have available content from
the working tree.

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:
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
346
                            # the file seems to have disappeared after being
367
358
                        statvalue, None))
368
359
        finally:
369
360
            if -1 == closedir(the_dir):
370
 
                raise_os_error(errno, "closedir: ", path)
 
361
                raise OSError(errno, "closedir: " + strerror(errno), path)
371
362
    finally:
372
363
        if -1 != orig_dir_fd:
373
364
            failed = False
375
366
                # try to close the original directory anyhow
376
367
                failed = True
377
368
            if -1 == close(orig_dir_fd) or failed:
378
 
                raise_os_error(errno, "return to orig_dir: ", "")
 
369
                raise OSError(errno, "return to orig_dir: " + strerror(errno))
379
370
 
380
371
    return result
381
372