| 507 | } |
| 508 | |
| 509 | fn save_lifecycle(dir: &Path, lifecycle: &ManagedLifecycle) -> CliResult<()> { |
| 510 | validate_run_id(&lifecycle.run_id)?; |
| 511 | fs::create_dir_all(dir)?; |
| 512 | let path = lifecycle_path(dir, &lifecycle.run_id); |
| 513 | let data = serde_json::to_vec_pretty(lifecycle) |
| 514 | .map_err(|e| CliError::Internal(anyhow!("failed to serialize managed lifecycle: {}", e)))?; |
| 515 | let tmp = path.with_extension("json.tmp"); |
| 516 | fs::write(&tmp, data)?; |
| 517 | fs::rename(&tmp, &path)?; |
| 518 | Ok(()) |
| 519 | } |
| 520 | |
| 521 | fn remove_lifecycle(dir: &Path, run_id: &str) -> CliResult<()> { |
| 522 | validate_run_id(run_id)?; |