Walk up from *start* looking for an existing ``.opentrace/`` directory. Security boundaries: - Stops at the git repo root (or filesystem root). - Rejects symlinks that resolve outside the boundary. - Caps upward traversal at ``_MAX_WALK_DEPTH`` levels.
(start: Path | None = None)
| 69 | |
| 70 | |
| 71 | def _find_opentrace_dir(start: Path | None = None) -> Path | None: |
| 72 | """Walk up from *start* looking for an existing ``.opentrace/`` directory. |
| 73 | |
| 74 | Security boundaries: |
| 75 | - Stops at the git repo root (or filesystem root). |
| 76 | - Rejects symlinks that resolve outside the boundary. |
| 77 | - Caps upward traversal at ``_MAX_WALK_DEPTH`` levels. |
| 78 | """ |
| 79 | if start is None: |
| 80 | start = Path.cwd() |
| 81 | start = start.resolve() |
| 82 | |
| 83 | git_root = _find_git_root(start) |
| 84 | # Use git root as boundary only if start is inside it. |
| 85 | boundary = git_root if git_root and _is_under(start, git_root) else Path(start.anchor) |
| 86 | |
| 87 | current = start |
| 88 | for _ in range(_MAX_WALK_DEPTH): |
| 89 | candidate = current / OPENTRACE_DIR |
| 90 | if candidate.is_dir(): |
| 91 | resolved = candidate.resolve() |
| 92 | # Reject if the resolved path escapes the repo boundary. |
| 93 | if _is_under(resolved, boundary): |
| 94 | return resolved |
| 95 | # Stop at boundary or filesystem root. |
| 96 | if current == boundary or current.parent == current: |
| 97 | break |
| 98 | current = current.parent |
| 99 | |
| 100 | return None |
| 101 | |
| 102 | |
| 103 | def find_db(start: Path | None = None) -> Path | None: |
no test coverage detected