(scan_dir: Path, file_name: str, *, required: bool)
| 3507 | |
| 3508 | |
| 3509 | def artifact_path(scan_dir: Path, file_name: str, *, required: bool) -> Path | None: |
| 3510 | scan_dir = require_canonical_scan_directory(scan_dir) |
| 3511 | candidate = scan_dir / file_name |
| 3512 | try: |
| 3513 | resolved = candidate.resolve(strict=True) |
| 3514 | resolved.relative_to(scan_dir.resolve()) |
| 3515 | except (FileNotFoundError, RuntimeError, ValueError) as exc: |
| 3516 | if not required and isinstance(exc, FileNotFoundError): |
| 3517 | return None |
| 3518 | raise SystemExit( |
| 3519 | f"{file_name}: expected a regular file inside the scan directory." |
| 3520 | ) from exc |
| 3521 | if resolved != candidate or not candidate.is_file(): |
| 3522 | raise SystemExit(f"{file_name}: expected a regular non-symlink file.") |
| 3523 | return resolved |
| 3524 | |
| 3525 | |
| 3526 | def require_canonical_scan_directory(scan_dir: Path) -> Path: |
no test coverage detected