/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

  • Committer: Robert Collins
  • Date: 2008-08-20 02:07:36 UTC
  • mfrom: (3640 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20080820020736-g2xe4921zzxtymle
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Bazaar-NG -- distributed version control
2
 
#
3
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006, 2008 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
26
24
# the opaque C library DIR type.
27
25
cdef extern from 'errno.h':
28
26
    int ENOENT
 
27
    int ENOTDIR
 
28
    int EAGAIN
29
29
    int errno
30
30
    char *strerror(int errno)
31
31
 
48
48
        unsigned char d_type
49
49
    ctypedef struct DIR
50
50
    # should be DIR *, pyrex barfs.
51
 
    DIR * opendir(char * name) except NULL
52
 
    int closedir(DIR * dir) except -1
 
51
    DIR * opendir(char * name)
 
52
    int closedir(DIR * dir)
53
53
    dirent *readdir(DIR *dir)
54
54
 
55
55
_directory = 'directory'
77
77
    # currently this needs a fixup - the C code says 'dirent' but should say
78
78
    # 'struct dirent'
79
79
    cdef dirent * entry
80
 
    cdef char *name 
 
80
    cdef dirent sentinel
 
81
    cdef char *name
81
82
    the_dir = opendir(path)
 
83
    if NULL == the_dir:
 
84
        raise OSError(errno, strerror(errno))
82
85
    result = []
83
86
    try:
84
 
        entry = readdir(the_dir)
 
87
        entry = &sentinel
85
88
        while entry != NULL:
 
89
            entry = readdir(the_dir)
 
90
            if entry == NULL:
 
91
                if errno == EAGAIN:
 
92
                    # try again
 
93
                    continue
 
94
                elif errno != ENOTDIR and errno != ENOENT and errno != 0:
 
95
                    # We see ENOTDIR at the end of a normal directory.
 
96
                    # As ENOTDIR for read_dir(file) is triggered on opendir,
 
97
                    # we consider ENOTDIR to be 'no error'.
 
98
                    # ENOENT is listed as 'invalid position in the dir stream' for
 
99
                    # readdir. We swallow this for now and just keep reading.
 
100
                    raise OSError(errno, strerror(errno))
 
101
                else:
 
102
                    # done
 
103
                    continue
86
104
            name = entry.d_name
87
105
            if not (name[0] == dot and (
88
106
                (name[1] == 0) or 
104
122
                    type = _block
105
123
                else:
106
124
                    type = _unknown
107
 
                result.append((entry.d_name, type))
108
 
            entry = readdir(the_dir)
109
 
        if entry == NULL and errno != ENOENT and errno != 0:
110
 
            # ENOENT is listed as 'invalid position in the dir stream' for
111
 
            # readdir. We swallow this for now.
 
125
                # result.append((entry.d_name, type))
 
126
                result.append((entry.d_name, 'unknown'))
 
127
    finally:
 
128
        if -1 == closedir(the_dir):
112
129
            raise OSError(errno, strerror(errno))
113
 
    finally:
114
 
        closedir(the_dir)
115
130
    return result
 
131
 
 
132
 
 
133
# vim: tw=79 ai expandtab sw=4 sts=4