plugin_framework, ignore loading uninstalled plugins

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-05-16 12:15:37 +08:00
parent 1747766f73
commit d985bd5607
2 changed files with 21 additions and 5 deletions

View File

@ -97,8 +97,15 @@ pub fn init() {
log::error!("Failed to remove plugins: {}", e);
}
}
if let Err(e) = plugins::load_plugins() {
log::error!("Failed to load plugins: {}", e);
match manager::get_uninstall_id_set() {
Ok(ids) => {
if let Err(e) = plugins::load_plugins(&ids) {
log::error!("Failed to load plugins: {}", e);
}
}
Err(e) => {
log::error!("Failed to load plugins: {}", e);
}
}
}

View File

@ -11,7 +11,7 @@ use hbb_common::{
};
use serde_derive::Serialize;
use std::{
collections::HashMap,
collections::{HashMap, HashSet},
ffi::{c_char, c_void},
path::PathBuf,
sync::{Arc, RwLock},
@ -263,7 +263,7 @@ const DYLIB_SUFFIX: &str = ".so";
#[cfg(target_os = "macos")]
const DYLIB_SUFFIX: &str = ".dylib";
pub(super) fn load_plugins() -> ResultType<()> {
pub(super) fn load_plugins(uninstalled_ids: &HashSet<String>) -> ResultType<()> {
let plugins_dir = super::get_plugins_dir()?;
if !plugins_dir.exists() {
std::fs::create_dir_all(&plugins_dir)?;
@ -273,7 +273,16 @@ pub(super) fn load_plugins() -> ResultType<()> {
Ok(entry) => {
let plugin_dir = entry.path();
if plugin_dir.is_dir() {
load_plugin_dir(&plugin_dir);
if let Some(plugin_id) = plugin_dir.file_name().and_then(|f| f.to_str()) {
if uninstalled_ids.contains(plugin_id) {
log::debug!(
"Ignore loading '{}' as it should be uninstalled",
plugin_id
);
continue;
}
load_plugin_dir(&plugin_dir);
}
}
}
Err(e) => {