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.
This commit is contained in:
Wang Han
2025-02-17 09:15:04 +08:00
committed by GitHub
parent 500ff9bcbc
commit ce13d050ca

View File

@@ -279,6 +279,18 @@ pub fn prune_modules() -> Result<()> {
Ok(()) 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(()) Ok(())
} }