Save lockfile data to disk with locking.
(self)
| 69 | return self._data |
| 70 | |
| 71 | def _save(self) -> bool: |
| 72 | """Save lockfile data to disk with locking.""" |
| 73 | if self._data is None: |
| 74 | return False |
| 75 | |
| 76 | try: |
| 77 | # Ensure parent directory exists |
| 78 | self.lockfile_path.parent.mkdir(parents=True, exist_ok=True) |
| 79 | |
| 80 | # Update timestamp |
| 81 | self._data["updated_at"] = datetime.now().isoformat() |
| 82 | |
| 83 | # Use write lock to prevent concurrent modifications |
| 84 | lock: FileLock = write_lock(self.lockfile_path) |
| 85 | with lock: |
| 86 | with open(self.lockfile_path, "w") as f: |
| 87 | json.dump(self._data, f, indent=2, sort_keys=True) |
| 88 | |
| 89 | return True |
| 90 | |
| 91 | except OSError as e: |
| 92 | logger.warning(f"Failed to save lockfile {self.lockfile_path}: {e}") |
| 93 | return False |
| 94 | |
| 95 | def get_pinned_version( |
| 96 | self, package_name: str, requirement: str, package_type: str = "tool" |
no test coverage detected