aKode update: il ripristino del binario non sovrascrive mai il file in uso

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 15:00:00 +01:00
parent 9494b768dd
commit e1ce139a80

View File

@@ -497,7 +497,12 @@ fn restore_binary(backup: &Path, exe: &Path) {
if cfg!(windows) { if cfg!(windows) {
let _ = std::fs::rename(backup, exe); let _ = std::fs::rename(backup, exe);
} else { } else {
let _ = std::fs::copy(backup, exe); // Copy to a fresh file and rename: overwriting the binary in place would corrupt a
// running executable (and invalidate its code signature on macOS).
let restored = exe.with_file_name(format!(".akode.restore-{}", std::process::id()));
if std::fs::copy(backup, &restored).is_ok() && std::fs::rename(&restored, exe).is_err() {
let _ = std::fs::remove_file(&restored);
}
} }
} }