Returns whether the path is a symbolic link that points outside the root directory. Also returns True if we failed to resolve the path.
(
path: Path,
root: Path,
report: Report | None = None,
)
| 253 | |
| 254 | |
| 255 | def resolves_outside_root_or_cannot_stat( |
| 256 | path: Path, |
| 257 | root: Path, |
| 258 | report: Report | None = None, |
| 259 | ) -> bool: |
| 260 | """ |
| 261 | Returns whether the path is a symbolic link that points outside the |
| 262 | root directory. Also returns True if we failed to resolve the path. |
| 263 | """ |
| 264 | try: |
| 265 | resolved_path = _cached_resolve(path) |
| 266 | except OSError as e: |
| 267 | if report: |
| 268 | report.path_ignored(path, f"cannot be read because {e}") |
| 269 | return True |
| 270 | try: |
| 271 | resolved_path.relative_to(root) |
| 272 | except ValueError: |
| 273 | if report: |
| 274 | report.path_ignored(path, f"is a symbolic link that points outside {root}") |
| 275 | return True |
| 276 | return False |
| 277 | |
| 278 | |
| 279 | def best_effort_relative_path(path: Path, root: Path) -> Path: |
no test coverage detected