1use crate::config::Config;
4use anyhow::{Result, bail};
5use shine_core::plan::PermissionV1;
6
7pub async fn handle_recover_approved(config: &Config, yes: bool) -> Result<()> {
8 let reviewed = crate::lifecycle_plan::review_plans(
9 config,
10 [crate::lifecycle_plan::LifecyclePlanRequest::app_recovery()],
11 yes,
12 )
13 .await?
14 .into_iter()
15 .next()
16 .expect("one reviewed App recovery Plan");
17 if reviewed
18 .approval
19 .approved_permissions
20 .contains(&PermissionV1::Administrator)
21 && !crate::privilege::ensure_admin(1).await?
22 {
23 bail!("administrator permission was not granted");
24 }
25 let runtime = crate::lifecycle_plan::prepare_runtime(config, &reviewed).await?;
26 let report = runtime
27 .recover_app_operation_approved(&reviewed.approval)
28 .await?;
29
30 if report.rolled_back_actions.is_empty() {
31 println!(
32 "App recovery complete: cleared the interrupted operation journal; no transaction-created files were removed."
33 );
34 } else {
35 println!(
36 "App recovery complete: rolled back {} interrupted file change(s) and cleared the operation journal.",
37 report.rolled_back_actions.len()
38 );
39 }
40 Ok(())
41}