MCPcopy
hub / github.com/opentrace/opentrace / _find_opentrace_dir

Function _find_opentrace_dir

agent/src/opentrace_agent/cli/main.py:71–100  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

69
70
71def _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
103def find_db(start: Path | None = None) -> Path | None:

Callers 5

get_api_tokenFunction · 0.90
find_dbFunction · 0.85
_resolve_config_pathFunction · 0.85
loginFunction · 0.85
whoamiFunction · 0.85

Calls 3

_find_git_rootFunction · 0.85
_is_underFunction · 0.85
rangeFunction · 0.85

Tested by

no test coverage detected