| 779 | |
| 780 | |
| 781 | def _write_system_status_cache(status: dict[str, Any], expires_at: float) -> None: |
| 782 | temp_path: Path | None = None |
| 783 | try: |
| 784 | with tempfile.NamedTemporaryFile( |
| 785 | delete=False, |
| 786 | dir=PROJECT_DIR, |
| 787 | encoding="utf-8", |
| 788 | mode="w", |
| 789 | suffix=".meta-cache.json", |
| 790 | ) as file: |
| 791 | json.dump({"expires_at": expires_at, "status": status}, file) |
| 792 | temp_path = Path(file.name) |
| 793 | os.replace(temp_path, SYSTEM_META_CACHE_PATH) |
| 794 | except OSError: |
| 795 | pass |
| 796 | finally: |
| 797 | if temp_path and temp_path.exists(): |
| 798 | try: |
| 799 | temp_path.unlink() |
| 800 | except OSError: |
| 801 | pass |
| 802 | |
| 803 | |
| 804 | def _cached_status(force: bool = False) -> dict[str, Any]: |