ksud: Add uninstall

This commit is contained in:
weishu
2024-04-22 20:41:42 +08:00
parent 4922d89823
commit 0697db618e
3 changed files with 30 additions and 4 deletions

View File

@@ -604,13 +604,21 @@ pub fn disable_module(id: &str) -> Result<()> {
}
pub fn disable_all_modules() -> Result<()> {
mark_all_modules(defs::DISABLE_FILE_NAME)
}
pub fn uninstall_all_modules() -> Result<()> {
mark_all_modules(defs::REMOVE_FILE_NAME)
}
fn mark_all_modules(flag_file: &str) -> Result<()> {
// we assume the module dir is already mounted
let dir = std::fs::read_dir(defs::MODULE_DIR)?;
for entry in dir.flatten() {
let path = entry.path();
let disable_flag = path.join(defs::DISABLE_FILE_NAME);
if let Err(e) = ensure_file_exists(disable_flag) {
warn!("Failed to disable module: {}: {}", path.display(), e);
let flag = path.join(flag_file);
if let Err(e) = ensure_file_exists(flag) {
warn!("Failed to mark module: {}: {}", path.display(), e);
}
}