| 863 | } |
| 864 | |
| 865 | fn save_lifecycle(dir: &Path, lifecycle: &ManagedLifecycle) -> CliResult<()> { |
| 866 | validate_run_id(&lifecycle.run_id)?; |
| 867 | fs::create_dir_all(dir)?; |
| 868 | let path = lifecycle_path(dir, &lifecycle.run_id); |
| 869 | let data = serde_json::to_vec_pretty(lifecycle) |
| 870 | .map_err(|e| CliError::Internal(anyhow!("failed to serialize managed lifecycle: {}", e)))?; |
| 871 | let tmp = path.with_extension("json.tmp"); |
| 872 | fs::write(&tmp, data)?; |
| 873 | fs::rename(&tmp, &path)?; |
| 874 | Ok(()) |
| 875 | } |
| 876 | |
| 877 | fn remove_lifecycle(dir: &Path, run_id: &str) -> CliResult<()> { |
| 878 | validate_run_id(run_id)?; |