Changeset ferringb%2Fpkgcore-dev,3507

Show
Ignore:
Timestamp:
06/28/08 13:18:51 (8 weeks ago)
Author:
Brian Harring <ferringb@…>
Message:

ticket 193; modify iter_scan (and friends) to support follow_symlinks, which switches the statter internally to os.stat, falling back to os.lstat when the link cannot be followed. option is not recommended, may be removed down the link- interim, it kills off 193.

Location:
ferringb/pkgcore-dev
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • ferringb/pkgcore-dev/NEWS

    r3503 r3507  
    44See ChangeLog for full commit logs; this is summarized/major changes. 
    55 
     6 
     7* ticket 193; follow symlinks in /etc/portage/*/ directories. 
    68 
    79* ticket 203; functionfoo() {:;} is not function 'foo', it's 'functionfoo'. 
  • ferringb/pkgcore-dev/pkgcore/ebuild/domain.py

    r3506 r3507  
    146146                        # means we get a nice exception w/o having to set it 
    147147                        # ourselves. 
    148                         for file in iter_scan(fp): 
     148                        for file in iter_scan(fp, follow_symlinks=True): 
    149149                            if any(True for thing in file.location.split('/') 
    150150                                if thing.startswith('.')): 
  • ferringb/pkgcore-dev/pkgcore/fs/livefs.py

    r3462 r3507  
    2828 
    2929 
    30 def gen_obj(path, stat=None, chksum_handlers=None, real_location=None): 
     30def gen_obj(path, stat=None, chksum_handlers=None, real_location=None, 
     31    stat_func=os.lstat): 
    3132 
    3233    """ 
     
    4344        real_location = path 
    4445    if stat is None: 
    45         stat = os.lstat(real_location) 
     46        try: 
     47            stat = stat_func(real_location) 
     48        except (IOError, OSError), e: 
     49            if stat_func == os.lstat or e.errno != errno.ENOENT: 
     50                raise 
     51            stat = os.lstat(real_location) 
    4652    if chksum_handlers is None: 
    4753        chksum_handlers = get_handlers() 
     
    7884# os.path.sep, not '/' :P) 
    7985 
    80 def _internal_iter_scan(path, chksum_handlers): 
     86def _internal_iter_scan(path, chksum_handlers, stat_func=os.lstat): 
    8187    dirs = collections.deque([normpath(path)]) 
    82     yield gen_obj(dirs[0], chksum_handlers=chksum_handlers) 
     88    yield gen_obj(dirs[0], chksum_handlers=chksum_handlers, 
     89        stat_func=stat_func) 
    8390    while dirs: 
    8491        base = dirs.popleft() 
     
    8693            path = pjoin(base, x) 
    8794            o = gen_obj(path, chksum_handlers=chksum_handlers, 
    88                         real_location=path) 
     95                        real_location=path, stat_func=stat_func) 
    8996            yield o 
    9097            if isinstance(o, fsDir): 
     
    9299 
    93100 
    94 def _internal_offset_iter_scan(path, chksum_handlers, offset): 
     101def _internal_offset_iter_scan(path, chksum_handlers, offset, 
     102    stat_func=os.lstat): 
    95103    offset = normpath(offset) 
    96104    path = normpath(path) 
    97105    dirs = collections.deque([path[len(offset):]]) 
    98106    if dirs[0]: 
    99         yield gen_obj(dirs[0], chksum_handlers=chksum_handlers) 
     107        yield gen_obj(dirs[0], chksum_handlers=chksum_handlers, 
     108            stat_func=stat_func) 
    100109 
    101110    sep = os.path.sep 
     
    107116            path = pjoin(base, x) 
    108117            o = gen_obj(path, chksum_handlers=chksum_handlers, 
    109                         real_location=pjoin(real_base, x)) 
     118                        real_location=pjoin(real_base, x), 
     119                        stat_func=os.lstat) 
    110120            yield o 
    111121            if isinstance(o, fsDir): 
     
    113123 
    114124 
    115 def iter_scan(path, offset=None): 
     125def iter_scan(path, offset=None, follow_symlinks=False): 
    116126    """ 
    117127    Recursively scan a path. 
     
    128138    chksum_handlers = get_handlers() 
    129139 
     140    stat_func = follow_symlinks and os.stat or os.lstat 
    130141    if offset is None: 
    131         return _internal_iter_scan(path, chksum_handlers) 
    132     return _internal_offset_iter_scan(path, chksum_handlers, offset) 
     142        return _internal_iter_scan(path, chksum_handlers, stat_func) 
     143    return _internal_offset_iter_scan(path, chksum_handlers, offset, stat_func) 
    133144 
    134145