~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_readdir_pyx.pyx

  • Committer: Robert Collins
  • Date: 2008-08-20 03:30:17 UTC
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20080820033017-q8y6stxz8f5kxu9y
Update readdir pyrex source files and usage in line with current practice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Wrapper for readdir which grabs file type from d_type."""
 
17
"""Wrapper for readdir which returns files ordered by inode."""
18
18
 
19
19
 
20
20
import os
46
46
        # this will fail to compile if d_type is not defined.
47
47
        # if this module fails to compile, use the .py version.
48
48
        unsigned char d_type
 
49
        int d_ino
49
50
    ctypedef struct DIR
50
51
    # should be DIR *, pyrex barfs.
51
52
    DIR * opendir(char * name)
71
72
    """Like os.listdir, this reads a directories contents.
72
73
 
73
74
    :param path: the directory to list.
74
 
    :return: a list of (basename, kind) tuples.
 
75
    :return: a list of (sort_key, basename) tuples.
75
76
    """
76
77
    cdef DIR *the_dir
77
78
    # currently this needs a fixup - the C code says 'dirent' but should say
106
107
                (name[1] == 0) or 
107
108
                (name[1] == dot and name [2] == 0))
108
109
                ):
109
 
                if entry.d_type == DT_UNKNOWN:
110
 
                    type = _unknown
111
 
                elif entry.d_type == DT_REG:
112
 
                    type = _file
113
 
                elif entry.d_type == DT_DIR:
114
 
                    type = _directory
115
 
                elif entry.d_type == DT_FIFO:
116
 
                    type = _fifo
117
 
                elif entry.d_type == DT_SOCK:
118
 
                    type = _socket
119
 
                elif entry.d_type == DT_CHR:
120
 
                    type = _chardev
121
 
                elif entry.d_type == DT_BLK:
122
 
                    type = _block
123
 
                else:
124
 
                    type = _unknown
125
 
                # result.append((entry.d_name, type))
126
 
                result.append((entry.d_name, 'unknown'))
 
110
                result.append((entry.d_ino, entry.d_name))
127
111
    finally:
128
112
        if -1 == closedir(the_dir):
129
113
            raise OSError(errno, strerror(errno))