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)
| 260 | |
| 261 | |
| 262 | def _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 | |
| 293 | def resolve_so_redirects(root: Path) -> dict[str, int]: |
no test coverage detected