| 767 | } |
| 768 | |
| 769 | fn list_lifecycles(dir: &Path) -> Vec<ManagedLifecycle> { |
| 770 | let entries = match fs::read_dir(dir) { |
| 771 | Ok(entries) => entries, |
| 772 | Err(_) => return Vec::new(), |
| 773 | }; |
| 774 | |
| 775 | let mut lifecycles = Vec::new(); |
| 776 | for entry in entries.flatten() { |
| 777 | let path = entry.path(); |
| 778 | if path.extension().and_then(|e| e.to_str()) != Some("json") { |
| 779 | continue; |
| 780 | } |
| 781 | let Ok(data) = fs::read_to_string(&path) else { |
| 782 | continue; |
| 783 | }; |
| 784 | let Ok(mut lifecycle) = serde_json::from_str::<ManagedLifecycle>(&data) else { |
| 785 | log::warn!("skipping unparseable lifecycle file {}", path.display()); |
| 786 | continue; |
| 787 | }; |
| 788 | if lifecycle.refusal.is_none() { |
| 789 | lifecycle.refusal = load_first_refusal(dir, &lifecycle.run_id) |
| 790 | .inspect_err(|error| { |
| 791 | log::warn!( |
| 792 | "could not read refusal for managed lifecycle '{}': {}", |
| 793 | lifecycle.run_id, |
| 794 | error, |
| 795 | ); |
| 796 | }) |
| 797 | .ok() |
| 798 | .flatten(); |
| 799 | } |
| 800 | lifecycles.push(lifecycle); |
| 801 | } |
| 802 | lifecycles |
| 803 | } |
| 804 | |
| 805 | fn cleanup_expired(dir: &Path, now: i64) { |
| 806 | let entries = match fs::read_dir(dir) { |