ksud: copy file when rename failed

This commit is contained in:
tiann 2023-02-21 23:52:04 +08:00
parent c3ba483b81
commit fafdacfc41
No known key found for this signature in database
GPG Key ID: 6D3F65FFD9559C06

View File

@ -218,11 +218,20 @@ pub fn on_services() -> Result<()> {
pub fn on_boot_completed() -> Result<()> {
crate::ksu::report_boot_complete();
info!("on_boot_completed triggered!");
let module_update_img = Path::new(defs::MODULE_UPDATE_IMG);
let module_img = Path::new(defs::MODULE_IMG);
if module_update_img.exists() {
// this is a update and we successfully booted
std::fs::rename(module_update_img, module_img)?;
if std::fs::rename(module_update_img, module_img).is_err() {
warn!(
"Failed to rename {} to {}, copy it now.",
module_update_img.display(),
module_img.display()
);
std::fs::copy(module_update_img, module_img)
.with_context(|| "Failed to copy modules_update.img to modules.img")?;
}
}
Ok(())
}