~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-14 17:08:56 UTC
  • mfrom: (3629 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3633.
  • Revision ID: john@arbash-meinel.com-20080814170856-p2ie5z7l6vowrftz
merge bzr.dev 3629, update NEWS entry to be in correct location.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1119
1119
        raise errors.IllegalPath(path)
1120
1120
 
1121
1121
 
 
1122
_WIN32_ERROR_DIRECTORY = 267 # Similar to errno.ENOTDIR
 
1123
 
 
1124
def _is_error_enotdir(e):
 
1125
    """Check if this exception represents ENOTDIR.
 
1126
 
 
1127
    Unfortunately, python is very inconsistent about the exception
 
1128
    here. The cases are:
 
1129
      1) Linux, Mac OSX all versions seem to set errno == ENOTDIR
 
1130
      2) Windows, Python2.4, uses errno == ERROR_DIRECTORY (267)
 
1131
         which is the windows error code.
 
1132
      3) Windows, Python2.5 uses errno == EINVAL and
 
1133
         winerror == ERROR_DIRECTORY
 
1134
 
 
1135
    :param e: An Exception object (expected to be OSError with an errno
 
1136
        attribute, but we should be able to cope with anything)
 
1137
    :return: True if this represents an ENOTDIR error. False otherwise.
 
1138
    """
 
1139
    en = getattr(e, 'errno', None)
 
1140
    if (en == errno.ENOTDIR
 
1141
        or (sys.platform == 'win32'
 
1142
            and (en == _WIN32_ERROR_DIRECTORY
 
1143
                 or (en == errno.EINVAL
 
1144
                     and getattr(e, 'winerror', None) == _WIN32_ERROR_DIRECTORY)
 
1145
        ))):
 
1146
        return True
 
1147
    return False
 
1148
 
 
1149
 
1122
1150
def walkdirs(top, prefix=""):
1123
1151
    """Yield data about all the directories in a tree.
1124
1152
    
1168
1196
 
1169
1197
        dirblock = []
1170
1198
        append = dirblock.append
1171
 
        for name in sorted(_listdir(top)):
1172
 
            abspath = top_slash + name
1173
 
            statvalue = _lstat(abspath)
1174
 
            kind = _kind_from_mode(statvalue.st_mode & 0170000, 'unknown')
1175
 
            append((relprefix + name, name, kind, statvalue, abspath))
 
1199
        try:
 
1200
            names = sorted(_listdir(top))
 
1201
        except OSError, e:
 
1202
            if not _is_error_enotdir(e):
 
1203
                raise
 
1204
        else:
 
1205
            for name in names:
 
1206
                abspath = top_slash + name
 
1207
                statvalue = _lstat(abspath)
 
1208
                kind = _kind_from_mode(statvalue.st_mode & 0170000, 'unknown')
 
1209
                append((relprefix + name, name, kind, statvalue, abspath))
1176
1210
        yield (relroot, top), dirblock
1177
1211
 
1178
1212
        # push the user specified dirs from dirblock