|
31 | 31 | GitWorktreeFileSystemItem,
|
32 | 32 | iter_gitworktree
|
33 | 33 | )
|
| 34 | +from .utils import FileSystemItemType |
34 | 35 |
|
35 | 36 |
|
36 | 37 | lgr = logging.getLogger('datalad.ext.next.iter_collections.annexworktree')
|
@@ -83,7 +84,7 @@ def iter_annexworktree(
|
83 | 84 |
|
84 | 85 | The basic semantics of all arguments are identical to
|
85 | 86 | :func:`~datalad_next.iter_collections.gitworktree.iter_gitworktree`.
|
86 |
| - Importantly, with ``fp=True``, the annex object is opened directly, |
| 87 | + Importantly, with ``fp=True``, an annex object is opened directly, |
87 | 88 | if available. If not available, no attempt is made to open the associated
|
88 | 89 | symlink or pointer file.
|
89 | 90 |
|
@@ -240,19 +241,31 @@ def iter_annexworktree(
|
240 | 241 | path = Path(path)
|
241 | 242 | for res in results:
|
242 | 243 | item = _get_worktree_item(path, get_fs_info=True, **res)
|
243 |
| - annexobjpath = res.get('annexobjpath') |
244 |
| - if not annexobjpath: |
245 |
| - # this is not an annexed file |
246 |
| - yield item |
247 |
| - continue |
248 |
| - full_annexobjpath = path / annexobjpath |
249 |
| - if not full_annexobjpath.exists(): |
250 |
| - # annexed object is not present |
251 |
| - yield item |
252 |
| - continue |
253 |
| - with (full_annexobjpath).open('rb') as active_fp: |
254 |
| - item.fp = active_fp |
| 244 | + # determine would file we would open |
| 245 | + fp_src = None |
| 246 | + if item.annexobjpath is not None: |
| 247 | + # this is an annexed file |
| 248 | + fp_src = item.annexobjpath |
| 249 | + elif item.type == FileSystemItemType.file \ |
| 250 | + and item.annexkey is None: |
| 251 | + # regular file (untracked or tracked) |
| 252 | + fp_src = item.name |
| 253 | + elif item.type == FileSystemItemType.symlink \ |
| 254 | + and item.annexkey is None: |
| 255 | + # regular symlink |
| 256 | + fp_src = item.name |
| 257 | + if fp_src is None: |
| 258 | + # nothing to open |
255 | 259 | yield item
|
| 260 | + else: |
| 261 | + fp_src_fullpath = path / fp_src |
| 262 | + if not fp_src_fullpath.exists(): |
| 263 | + # nothing there to open (would resolve through a symlink) |
| 264 | + yield item |
| 265 | + else: |
| 266 | + with fp_src_fullpath.open('rb') as active_fp: |
| 267 | + item.fp = active_fp |
| 268 | + yield item |
256 | 269 |
|
257 | 270 |
|
258 | 271 | def _get_worktree_item(
|
|
0 commit comments