| 463 | } |
| 464 | |
| 465 | fn cleanup_expired(dir: &Path, now: i64) { |
| 466 | let entries = match fs::read_dir(dir) { |
| 467 | Ok(entries) => entries, |
| 468 | Err(_) => return, |
| 469 | }; |
| 470 | for entry in entries.flatten() { |
| 471 | let path = entry.path(); |
| 472 | if path.extension().and_then(|e| e.to_str()) != Some("json") { |
| 473 | continue; |
| 474 | } |
| 475 | let expired = fs::read_to_string(&path) |
| 476 | .ok() |
| 477 | .and_then(|data| serde_json::from_str::<ManagedLifecycle>(&data).ok()) |
| 478 | .map(|l| l.is_expired(now)) |
| 479 | .unwrap_or(false); |
| 480 | if expired { |
| 481 | let _ = fs::remove_file(&path); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | fn load_lifecycle(dir: &Path, run_id: &str) -> CliResult<Option<ManagedLifecycle>> { |
| 487 | validate_run_id(run_id)?; |