MCPcopy Create free account
hub / github.com/idank/explainshell / _resolve_so_target

Function _resolve_so_target

tools/fetch_manned.py:262–290  ·  view source on GitHub ↗

Resolve a .so target string to an actual .gz file under *root*. Handles two formats: - "man / . " → root/ / . .gz - " . " → root/ / . .gz

(redirect_path: Path, so_target: str, root: Path)

Source from the content-addressed store, hash-verified

260
261
262def _resolve_so_target(redirect_path: Path, so_target: str, root: Path) -> Path | None:
263 """Resolve a .so target string to an actual .gz file under *root*.
264
265 Handles two formats:
266 - "man<N>/<name>.<N>" → root/<N>/<name>.<N>.gz
267 - "<name>.<N>" → root/<same-section>/<name>.<N>.gz
268 """
269 m = re.match(r"^man(\d+)/(.+)$", so_target)
270 if m:
271 section = m.group(1)
272 basename = m.group(2)
273 candidate = root / section / f"{basename}.gz"
274 if candidate.exists():
275 return candidate
276 # Upstream packaging bugs may embed junk path components
277 # (e.g. "man1/./build/man/podman-play.1"). Fall back to the
278 # filename only.
279 filename = Path(basename).name
280 if filename != basename:
281 candidate = root / section / f"{filename}.gz"
282 if candidate.exists():
283 return candidate
284 return None
285
286 # Bare filename — same section as the source file.
287 candidate = redirect_path.parent / f"{so_target}.gz"
288 if candidate.exists():
289 return candidate
290 return None
291
292
293def resolve_so_redirects(root: Path) -> dict[str, int]:

Callers 1

resolve_so_redirectsFunction · 0.85

Calls 1

matchMethod · 0.80

Tested by

no test coverage detected