~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_readdir_pyx.pyx

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

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
110
109
_directory = 'directory'
111
 
cdef object _chardev
112
110
_chardev = 'chardev'
113
 
cdef object _block
114
111
_block = 'block'
115
 
cdef object _file
116
112
_file = 'file'
117
 
cdef object _fifo
118
113
_fifo = 'fifo'
119
 
cdef object _symlink
120
114
_symlink = 'symlink'
121
 
cdef object _socket
122
115
_socket = 'socket'
123
 
cdef object _unknown
124
116
_unknown = 'unknown'
 
117
_missing = 'missing'
125
118
 
126
119
# add a typedef struct dirent dirent to workaround pyrex
127
120
cdef extern from 'readdir.h':
168
161
 
169
162
from bzrlib import osutils
170
163
 
171
 
cdef object _safe_utf8
172
 
_safe_utf8 = osutils.safe_utf8
173
164
 
174
165
cdef class UTF8DirReader:
175
166
    """A dir reader for utf8 file systems."""
176
167
 
 
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
 
177
183
    def kind_from_mode(self, int mode):
178
184
        """Get the kind of a path from a mode status."""
179
185
        return self._kind_from_mode(mode)
181
187
    cdef _kind_from_mode(self, int mode):
182
188
        # Files and directories are the most common - check them first.
183
189
        if S_ISREG(mode):
184
 
            return _file
 
190
            return self._file
185
191
        if S_ISDIR(mode):
186
 
            return _directory
 
192
            return self._directory
187
193
        if S_ISCHR(mode):
188
 
            return _chardev
 
194
            return self._chardev
189
195
        if S_ISBLK(mode):
190
 
            return _block
 
196
            return self._block
191
197
        if S_ISLNK(mode):
192
 
            return _symlink
 
198
            return self._symlink
193
199
        if S_ISFIFO(mode):
194
 
            return _fifo
 
200
            return self._fifo
195
201
        if S_ISSOCK(mode):
196
 
            return _socket
197
 
        return _unknown
 
202
            return self._socket
 
203
        return self._unknown
198
204
 
199
205
    def top_prefix_to_starting_dir(self, top, prefix=""):
200
206
        """See DirReader.top_prefix_to_starting_dir."""
201
 
        return (_safe_utf8(prefix), None, None, None, _safe_utf8(top))
 
207
        return (self._safe_utf8(prefix), None, None, None,
 
208
            self._safe_utf8(top))
202
209
 
203
210
    def read_dir(self, prefix, top):
204
211
        """Read a single directory from a utf8 file system.
300
307
        if orig_dir_fd == -1:
301
308
            raise_os_error(errno, "open: ", ".")
302
309
        if -1 == chdir(path):
303
 
            # Ignore the return value, because we are already raising an
304
 
            # exception
305
 
            close(orig_dir_fd)
306
310
            raise_os_error(errno, "chdir: ", path)
307
311
    else:
308
312
        orig_dir_fd = -1