Enhanced KPM module loading logic, added filename validation and error handling
This commit is contained in:
@@ -101,10 +101,23 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
|
|
||||||
run_stage("post-mount", true);
|
run_stage("post-mount", true);
|
||||||
|
|
||||||
|
// load kpm modules
|
||||||
for entry in std::fs::read_dir(kpm::KPM_DIR)? {
|
for entry in std::fs::read_dir(kpm::KPM_DIR)? {
|
||||||
let path = entry?.path();
|
let path = entry?.path();
|
||||||
|
if let Some(file_name) = path.file_stem() {
|
||||||
|
if let Some(file_name_str) = file_name.to_str() {
|
||||||
|
if file_name_str.is_empty() {
|
||||||
|
log::warn!("Invalid KPM file name: {}", path.display());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if path.extension().is_some_and(|ext| ext == "kpm") {
|
if path.extension().is_some_and(|ext| ext == "kpm") {
|
||||||
let _ = kpm::load_kpm(&path);
|
match kpm::load_kpm(&path) {
|
||||||
|
Ok(()) => log::info!("Successfully loaded KPM module: {}", path.display()),
|
||||||
|
Err(e) => log::warn!("Failed to load KPM module {}: {}", path.display(), e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,15 +75,28 @@ fn handle_remove_event(paths: Vec<std::path::PathBuf>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 加载 KPM 模块
|
// 加载 KPM 模块
|
||||||
pub fn load_kpm(path: &Path) -> Result<()> {
|
fn load_kpm_modules() -> Result<()> {
|
||||||
let path_str = path.to_str().ok_or_else(|| anyhow!("Invalid path: {}", path.display()))?;
|
if !Path::new(kpm::KPM_DIR).exists() {
|
||||||
let status = std::process::Command::new(KPMMGR_PATH)
|
log::warn!("KPM directory does not exist: {}", kpm::KPM_DIR);
|
||||||
.args(["load", path_str, ""])
|
return Ok(());
|
||||||
.status()?;
|
|
||||||
|
|
||||||
if status.success() {
|
|
||||||
log::info!("Loaded KPM: {}", path.display());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for entry in std::fs::read_dir(kpm::KPM_DIR)? {
|
||||||
|
let path = entry?.path();
|
||||||
|
if let Some(file_name) = path.file_stem() {
|
||||||
|
if let Some(file_name_str) = file_name.to_str() {
|
||||||
|
log::info!("Loading KPM module: {}", file_name_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if path.extension().is_some_and(|ext| ext == "kpm") {
|
||||||
|
match kpm::load_kpm(&path) {
|
||||||
|
Ok(()) => log::info!("Successfully loaded KPM module: {}", path.display()),
|
||||||
|
Err(e) => log::warn!("Failed to load KPM module {}: {}", path.display(), e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user