~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_readdir_pyx.pyx

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-21 13:36:51 UTC
  • mfrom: (5243.2.1 readdir_cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100521133651-p62dndo2giy5ls21
(lifeless) Some cleanups to the readdir pyrex code for a little efficiency
 and to avoid compile warnings. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
    int closedir(DIR * dir)
107
107
    dirent *readdir(DIR *dir)
108
108
 
 
109
cdef object _directory
109
110
_directory = 'directory'
 
111
cdef object _chardev
110
112
_chardev = 'chardev'
 
113
cdef object _block
111
114
_block = 'block'
 
115
cdef object _file
112
116
_file = 'file'
 
117
cdef object _fifo
113
118
_fifo = 'fifo'
 
119
cdef object _symlink
114
120
_symlink = 'symlink'
 
121
cdef object _socket
115
122
_socket = 'socket'
 
123
cdef object _unknown
116
124
_unknown = 'unknown'
117
 
_missing = 'missing'
118
125
 
119
126
# add a typedef struct dirent dirent to workaround pyrex
120
127
cdef extern from 'readdir.h':
161
168
 
162
169
from bzrlib import osutils
163
170
 
 
171
cdef object _safe_utf8
 
172
_safe_utf8 = osutils.safe_utf8
164
173
 
165
174
cdef class UTF8DirReader:
166
175
    """A dir reader for utf8 file systems."""
167
176
 
168
 
    cdef readonly object _safe_utf8
169
 
    cdef _directory, _chardev, _block, _file, _fifo, _symlink
170
 
    cdef _socket, _unknown
171
 
 
172
 
    def __init__(self):
173
 
        self._safe_utf8 = osutils.safe_utf8
174
 
        self._directory = _directory
175
 
        self._chardev = _chardev
176
 
        self._block = _block
177
 
        self._file = _file
178
 
        self._fifo = _fifo
179
 
        self._symlink = _symlink
180
 
        self._socket = _socket
181
 
        self._unknown = _unknown
182
 
 
183
177
    def kind_from_mode(self, int mode):
184
178
        """Get the kind of a path from a mode status."""
185
179
        return self._kind_from_mode(mode)
187
181
    cdef _kind_from_mode(self, int mode):
188
182
        # Files and directories are the most common - check them first.
189
183
        if S_ISREG(mode):
190
 
            return self._file
 
184
            return _file
191
185
        if S_ISDIR(mode):
192
 
            return self._directory
 
186
            return _directory
193
187
        if S_ISCHR(mode):
194
 
            return self._chardev
 
188
            return _chardev
195
189
        if S_ISBLK(mode):
196
 
            return self._block
 
190
            return _block
197
191
        if S_ISLNK(mode):
198
 
            return self._symlink
 
192
            return _symlink
199
193
        if S_ISFIFO(mode):
200
 
            return self._fifo
 
194
            return _fifo
201
195
        if S_ISSOCK(mode):
202
 
            return self._socket
203
 
        return self._unknown
 
196
            return _socket
 
197
        return _unknown
204
198
 
205
199
    def top_prefix_to_starting_dir(self, top, prefix=""):
206
200
        """See DirReader.top_prefix_to_starting_dir."""
207
 
        return (self._safe_utf8(prefix), None, None, None,
208
 
            self._safe_utf8(top))
 
201
        return (_safe_utf8(prefix), None, None, None, _safe_utf8(top))
209
202
 
210
203
    def read_dir(self, prefix, top):
211
204
        """Read a single directory from a utf8 file system.