| 437 | } |
| 438 | |
| 439 | fn list_active(dir: &Path, now: i64) -> Vec<ManagedLifecycle> { |
| 440 | let entries = match fs::read_dir(dir) { |
| 441 | Ok(entries) => entries, |
| 442 | Err(_) => return Vec::new(), |
| 443 | }; |
| 444 | |
| 445 | let mut active = Vec::new(); |
| 446 | for entry in entries.flatten() { |
| 447 | let path = entry.path(); |
| 448 | if path.extension().and_then(|e| e.to_str()) != Some("json") { |
| 449 | continue; |
| 450 | } |
| 451 | let Ok(data) = fs::read_to_string(&path) else { |
| 452 | continue; |
| 453 | }; |
| 454 | let Ok(lifecycle) = serde_json::from_str::<ManagedLifecycle>(&data) else { |
| 455 | log::warn!("skipping unparseable lifecycle file {}", path.display()); |
| 456 | continue; |
| 457 | }; |
| 458 | if !lifecycle.is_expired(now) { |
| 459 | active.push(lifecycle); |
| 460 | } |
| 461 | } |
| 462 | active |
| 463 | } |
| 464 | |
| 465 | fn cleanup_expired(dir: &Path, now: i64) { |
| 466 | let entries = match fs::read_dir(dir) { |