From 43d30c8f2bebed2a9d408b06eaae7989109d706f Mon Sep 17 00:00:00 2001 From: Wang Han <416810799@qq.com> Date: Mon, 17 Feb 2025 09:15:04 +0800 Subject: [PATCH] Drop module image if no module remaining (#2447) This fixes the issue that module image will always exist even if there is no module to be loaded. Sadly we need to boot twice because we can only know module status after image is mounted. --- userspace/ksud_overlayfs/src/module.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/userspace/ksud_overlayfs/src/module.rs b/userspace/ksud_overlayfs/src/module.rs index 7a5b5b22..96928563 100644 --- a/userspace/ksud_overlayfs/src/module.rs +++ b/userspace/ksud_overlayfs/src/module.rs @@ -281,6 +281,18 @@ pub fn prune_modules() -> Result<()> { Ok(()) })?; + // collect remaining modules, if none, remove img + let remaining_modules: Vec<_> = std::fs::read_dir(defs::MODULE_DIR)? + .filter_map(|entry| entry.ok()) + .filter(|entry| entry.path().join("module.prop").exists()) + .collect(); + + if remaining_modules.is_empty() { + info!("no remaining modules, deleting image files."); + std::fs::remove_file(defs::MODULE_IMG).ok(); + std::fs::remove_file(defs::MODULE_UPDATE_IMG).ok(); + } + Ok(()) }