Uninstall plugins from settings

This commit is contained in:
2026-05-07 23:28:36 -04:00
parent 8ec468f57e
commit eddd694ae9
6 changed files with 230 additions and 4 deletions
@@ -5,7 +5,7 @@ use std::{
};
use directories::ProjectDirs;
use ely_domain::PluginManifest;
use ely_domain::{PluginId, PluginManifest};
use thiserror::Error;
use super::plugin_packages::{PluginPackageError, PluginPackageReader, VerifiedPluginPackage};
@@ -59,6 +59,9 @@ pub enum PluginPackageStoreError {
#[error("failed to clean plugin package staging directory: {path}")]
CleanupFailed { path: PathBuf, source: io::Error },
#[error("failed to remove plugin package directory: {path}")]
RemoveDirectoryFailed { path: PathBuf, source: io::Error },
#[error("system clock is unavailable for plugin package staging")]
ClockUnavailable { source: SystemTimeError },
}
@@ -137,6 +140,15 @@ impl PluginPackageStore {
))
}
pub fn remove_plugin(&self, plugin_id: &PluginId) -> Result<(), PluginPackageStoreError> {
let path = self.root.join(plugin_id.as_str());
match fs::remove_dir_all(path.as_path()) {
Ok(()) => Ok(()),
Err(source) if source.kind() == io::ErrorKind::NotFound => Ok(()),
Err(source) => Err(PluginPackageStoreError::RemoveDirectoryFailed { path, source }),
}
}
fn package_path(&self, package: &VerifiedPluginPackage) -> PathBuf {
self.plugin_root(package).join(format!("{}.rplug", package.package_hash()))
}
@@ -296,6 +308,21 @@ mod tests {
Ok(())
}
#[test]
fn removes_stored_packages_for_plugin() -> Result<(), Box<dyn Error>> {
let tree = TempTree::new("remove")?;
let source_package = write_package(tree.path(), "verified", b"wasm component")?;
let package = PluginPackageReader::read_directory_package(source_package.as_path())?;
let store = PluginPackageStore::new(tree.path().join("store"));
let stored_package = store.store(&package)?;
store.remove_plugin(package.manifest().id())?;
assert!(!stored_package.path.exists());
assert!(!tree.path().join("store").join("com.elydora.verified").exists());
Ok(())
}
fn write_package(root: &Path, name: &str, component: &[u8]) -> Result<PathBuf, Box<dyn Error>> {
let package = root.join(format!("{name}.rplug"));
fs::create_dir_all(package.join("signatures"))?;