List all active locks in cache directory with metadata. Args: cache_dir: Global cache directory Returns: List of LockInfo objects
(cache_dir: Path)
| 162 | |
| 163 | |
| 164 | def list_active_locks(cache_dir: Path) -> list[LockInfo]: |
| 165 | """ |
| 166 | List all active locks in cache directory with metadata. |
| 167 | |
| 168 | Args: |
| 169 | cache_dir: Global cache directory |
| 170 | |
| 171 | Returns: |
| 172 | List of LockInfo objects |
| 173 | """ |
| 174 | if not cache_dir.exists(): |
| 175 | return [] |
| 176 | |
| 177 | locks: list[LockInfo] = [] |
| 178 | |
| 179 | # Query database for all locks |
| 180 | db = get_lock_database() |
| 181 | all_db_locks = db.list_all_locks() |
| 182 | |
| 183 | from ci.util.file_lock_rw_util import is_process_alive |
| 184 | |
| 185 | for lock in all_db_locks: |
| 186 | # Filter to locks relevant to this cache_dir |
| 187 | lock_name = lock["lock_name"] |
| 188 | if str(cache_dir) in lock_name: |
| 189 | pid = lock["owner_pid"] |
| 190 | stale = not is_process_alive(pid) |
| 191 | locks.append( |
| 192 | LockInfo( |
| 193 | path=lock_name, |
| 194 | pid=pid, |
| 195 | operation=lock["operation"], |
| 196 | timestamp=str(lock["acquired_at"]), |
| 197 | is_stale=stale, |
| 198 | hostname=lock["hostname"], |
| 199 | ) |
| 200 | ) |
| 201 | |
| 202 | return locks |
| 203 | |
| 204 | |
| 205 | def is_artifact_locked(cache_dir: Path, url: str) -> bool: |