Skip to main content

vs_core/service/
remove.rs

1//! Services for removing registered plugins.
2
3use std::fs;
4
5use crate::{App, CoreError, UseScope};
6
7impl App {
8    /// Removes a plugin, its source directory, and all installed SDK versions.
9    pub fn remove_plugin(&self, name: &str) -> Result<bool, CoreError> {
10        let removed = self.registry.remove_plugin(name)?;
11        if !removed {
12            return Ok(false);
13        }
14
15        // Unuse from global scope (ignore errors if not set).
16        let _ = self.unuse_tool(name, UseScope::Global);
17
18        // Remove plugin source directory.
19        let source_dir = self.home().join("plugins").join("sources").join(name);
20        if source_dir.exists() {
21            fs::remove_dir_all(&source_dir)?;
22        }
23
24        // Remove all installed SDK versions.
25        let cache_dir = self.home().join("cache").join(name);
26        if cache_dir.exists() {
27            fs::remove_dir_all(&cache_dir)?;
28        }
29
30        Ok(true)
31    }
32}