Changeset ferringb%2Fpkgcore-dev,3507
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r3503
|
r3507
|
|
| 4 | 4 | See ChangeLog for full commit logs; this is summarized/major changes. |
| 5 | 5 | |
| | 6 | |
| | 7 | * ticket 193; follow symlinks in /etc/portage/*/ directories. |
| 6 | 8 | |
| 7 | 9 | * ticket 203; functionfoo() {:;} is not function 'foo', it's 'functionfoo'. |
-
|
r3506
|
r3507
|
|
| 146 | 146 | # means we get a nice exception w/o having to set it |
| 147 | 147 | # ourselves. |
| 148 | | for file in iter_scan(fp): |
| | 148 | for file in iter_scan(fp, follow_symlinks=True): |
| 149 | 149 | if any(True for thing in file.location.split('/') |
| 150 | 150 | if thing.startswith('.')): |
-
|
r3462
|
r3507
|
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | | def gen_obj(path, stat=None, chksum_handlers=None, real_location=None): |
| | 30 | def gen_obj(path, stat=None, chksum_handlers=None, real_location=None, |
| | 31 | stat_func=os.lstat): |
| 31 | 32 | |
| 32 | 33 | """ |
| … |
… |
|
| 43 | 44 | real_location = path |
| 44 | 45 | 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) |
| 46 | 52 | if chksum_handlers is None: |
| 47 | 53 | chksum_handlers = get_handlers() |
| … |
… |
|
| 78 | 84 | # os.path.sep, not '/' :P) |
| 79 | 85 | |
| 80 | | def _internal_iter_scan(path, chksum_handlers): |
| | 86 | def _internal_iter_scan(path, chksum_handlers, stat_func=os.lstat): |
| 81 | 87 | 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) |
| 83 | 90 | while dirs: |
| 84 | 91 | base = dirs.popleft() |
| … |
… |
|
| 86 | 93 | path = pjoin(base, x) |
| 87 | 94 | o = gen_obj(path, chksum_handlers=chksum_handlers, |
| 88 | | real_location=path) |
| | 95 | real_location=path, stat_func=stat_func) |
| 89 | 96 | yield o |
| 90 | 97 | if isinstance(o, fsDir): |
| … |
… |
|
| 92 | 99 | |
| 93 | 100 | |
| 94 | | def _internal_offset_iter_scan(path, chksum_handlers, offset): |
| | 101 | def _internal_offset_iter_scan(path, chksum_handlers, offset, |
| | 102 | stat_func=os.lstat): |
| 95 | 103 | offset = normpath(offset) |
| 96 | 104 | path = normpath(path) |
| 97 | 105 | dirs = collections.deque([path[len(offset):]]) |
| 98 | 106 | 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) |
| 100 | 109 | |
| 101 | 110 | sep = os.path.sep |
| … |
… |
|
| 107 | 116 | path = pjoin(base, x) |
| 108 | 117 | 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) |
| 110 | 120 | yield o |
| 111 | 121 | if isinstance(o, fsDir): |
| … |
… |
|
| 113 | 123 | |
| 114 | 124 | |
| 115 | | def iter_scan(path, offset=None): |
| | 125 | def iter_scan(path, offset=None, follow_symlinks=False): |
| 116 | 126 | """ |
| 117 | 127 | Recursively scan a path. |
| … |
… |
|
| 128 | 138 | chksum_handlers = get_handlers() |
| 129 | 139 | |
| | 140 | stat_func = follow_symlinks and os.stat or os.lstat |
| 130 | 141 | 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) |
| 133 | 144 | |
| 134 | 145 | |