running_process/cleanup/
uninstall.rs1use std::path::Path;
2
3use crate::broker::manifest;
4use crate::cleanup::{delete_path, root_is_config, root_is_prunable, CleanupAction, CleanupError};
5
6pub fn run(
8 registry_dir: &Path,
9 service: &str,
10 keep_config: bool,
11 confirm: bool,
12) -> Result<Vec<CleanupAction>, CleanupError> {
13 let manifests = manifest::enumerate_central(registry_dir);
14 let mut actions = Vec::new();
15
16 for manifest in manifests {
17 if manifest.service_name != service {
18 continue;
19 }
20 for root in &manifest.roots {
21 let path = std::path::PathBuf::from(&root.path);
22 if keep_config && root_is_config(root) {
23 actions.push(CleanupAction {
24 service_name: manifest.service_name.clone(),
25 service_version: manifest.service_version.clone(),
26 path,
27 reason: "uninstall".to_string(),
28 deleted: false,
29 skipped: true,
30 skip_reason: Some("CACHE_CONFIG preserved by --keep-config".to_string()),
31 });
32 continue;
33 }
34 if !root_is_prunable(root) {
35 actions.push(CleanupAction {
36 service_name: manifest.service_name.clone(),
37 service_version: manifest.service_version.clone(),
38 path,
39 reason: "uninstall".to_string(),
40 deleted: false,
41 skipped: true,
42 skip_reason: Some("root disposition is not prunable".to_string()),
43 });
44 continue;
45 }
46 if confirm {
47 delete_path(&path)?;
48 }
49 actions.push(CleanupAction {
50 service_name: manifest.service_name.clone(),
51 service_version: manifest.service_version.clone(),
52 path,
53 reason: if confirm {
54 "uninstall-confirmed".to_string()
55 } else {
56 "uninstall-dry-run".to_string()
57 },
58 deleted: confirm,
59 skipped: false,
60 skip_reason: None,
61 });
62 }
63 }
64
65 Ok(actions)
66}