(path: Path, root: Path)
| 277 | |
| 278 | |
| 279 | def best_effort_relative_path(path: Path, root: Path) -> Path: |
| 280 | # Precondition: resolves_outside_root_or_cannot_stat(path, root) is False |
| 281 | try: |
| 282 | return path.absolute().relative_to(root) |
| 283 | except ValueError: |
| 284 | pass |
| 285 | root_parent = next((p for p in path.parents if _cached_resolve(p) == root), None) |
| 286 | if root_parent is not None: |
| 287 | return path.relative_to(root_parent) |
| 288 | # something adversarial, fallback to path guaranteed by precondition |
| 289 | return _cached_resolve(path).relative_to(root) |
| 290 | |
| 291 | |
| 292 | def _path_is_ignored( |
no test coverage detected