ksud: reclaim sparse space when install/uninstall modules. close #1367

This commit is contained in:
weishu
2024-02-19 15:27:27 +08:00
parent e0802b0d15
commit e0e7058d14
3 changed files with 101 additions and 0 deletions

View File

@@ -444,6 +444,10 @@ fn _install_module(zip: &str) -> Result<()> {
exec_install_script(zip)?;
if let Err(e) = utils::punch_hole(tmp_module_img) {
warn!("Failed to punch hole: {}", e);
}
info!("rename {tmp_module_img} to {}", defs::MODULE_UPDATE_IMG);
// all done, rename the tmp image to modules_update.img
if std::fs::rename(tmp_module_img, defs::MODULE_UPDATE_IMG).is_err() {
@@ -507,6 +511,10 @@ where
// call the operation func
let result = func(id, update_dir);
if let Err(e) = utils::punch_hole(modules_update_tmp_img) {
warn!("Failed to punch hole: {}", e);
}
if let Err(e) = std::fs::rename(modules_update_tmp_img, defs::MODULE_UPDATE_IMG) {
warn!("Rename image failed: {e}, try copy it.");
utils::copy_sparse_file(modules_update_tmp_img, defs::MODULE_UPDATE_IMG)