From d07956ead6c397df908cdc2a55688082d0a17d65 Mon Sep 17 00:00:00 2001 From: weishu Date: Tue, 11 Jul 2023 22:00:50 +0800 Subject: [PATCH] ksud: fix prune module --- userspace/ksud/src/module.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/userspace/ksud/src/module.rs b/userspace/ksud/src/module.rs index ec495e74..96de5374 100644 --- a/userspace/ksud/src/module.rs +++ b/userspace/ksud/src/module.rs @@ -89,20 +89,21 @@ fn mark_module_state(module: &str, flag_file: &str, create_or_delete: bool) -> R } } -fn foreach_active_module(mut f: impl FnMut(&Path) -> Result<()>) -> Result<()> { +fn foreach_module(active_only: bool, mut f: impl FnMut(&Path) -> Result<()>) -> Result<()> { let modules_dir = Path::new(defs::MODULE_DIR); let dir = std::fs::read_dir(modules_dir)?; for entry in dir.flatten() { let path = entry.path(); if !path.is_dir() { + warn!("{} is not a directory, skip", path.display()); continue; } - if path.join(defs::DISABLE_FILE_NAME).exists() { + if active_only && path.join(defs::DISABLE_FILE_NAME).exists() { info!("{} is disabled, skip", path.display()); continue; } - if path.join(defs::REMOVE_FILE_NAME).exists() { + if active_only && path.join(defs::REMOVE_FILE_NAME).exists() { warn!("{} is removed, skip", path.display()); continue; } @@ -113,6 +114,10 @@ fn foreach_active_module(mut f: impl FnMut(&Path) -> Result<()>) -> Result<()> { Ok(()) } +fn foreach_active_module(f: impl FnMut(&Path) -> Result<()>) -> Result<()> { + foreach_module(true, f) +} + fn get_minimal_image_size(img: &str) -> Result { check_image(img)?; @@ -308,7 +313,7 @@ pub fn load_system_prop() -> Result<()> { } pub fn prune_modules() -> Result<()> { - foreach_active_module(|module| { + foreach_module(false, |module| { remove_file(module.join(defs::UPDATE_FILE_NAME)).ok(); if !module.join(defs::REMOVE_FILE_NAME).exists() {