~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2006-06-13 12:55:45 UTC
  • mfrom: (1757.2.16 add)
  • mto: This revision was merged to the branch mainline in revision 1769.
  • Revision ID: robertc@robertcollins.net-20060613125545-cc77adde61a471bf
Merge add performance improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
 
109
109
 
110
110
def file_kind(f, _lstat=os.lstat, _mapper=file_kind_from_stat_mode):
111
 
    return _mapper(_lstat(f).st_mode)
 
111
    try:
 
112
        return _mapper(_lstat(f).st_mode)
 
113
    except OSError, e:
 
114
        if getattr(e, 'errno', None) == errno.ENOENT:
 
115
            raise bzrlib.errors.NoSuchFile(f)
 
116
        raise
112
117
 
113
118
 
114
119
def kind_marker(kind):
803
808
        raise IllegalPath(path)
804
809
 
805
810
 
806
 
def walkdirs(top):
 
811
def walkdirs(top, prefix=""):
807
812
    """Yield data about all the directories in a tree.
808
813
    
809
814
    This yields all the data about the contents of a directory at a time.
813
818
    The data yielded is of the form:
814
819
    [(relpath, basename, kind, lstat, path_from_top), ...]
815
820
 
 
821
    :param prefix: Prefix the relpaths that are yielded with 'prefix'. This 
 
822
        allows one to walk a subtree but get paths that are relative to a tree
 
823
        rooted higher up.
816
824
    :return: an iterator over the dirs.
817
825
    """
818
826
    lstat = os.lstat
819
827
    pending = []
820
828
    _directory = _directory_kind
821
829
    _listdir = listdir
822
 
    pending = [("", "", _directory, None, top)]
 
830
    pending = [(prefix, "", _directory, None, top)]
823
831
    while pending:
824
832
        dirblock = []
825
833
        currentdir = pending.pop()