added version number, fixed infinite update loop
This commit is contained in:
@@ -154,6 +154,37 @@ pub async fn download_and_apply(
|
||||
Ok(current_exe)
|
||||
}
|
||||
|
||||
// ── Update-target file ───────────────────────────────────────────────────────
|
||||
// Written just before exec. On next startup we compare the expected version
|
||||
// with CARGO_PKG_VERSION. A mismatch means the replacement didn't work
|
||||
// (wrong asset, failed rename, etc.) and we show an error instead of looping.
|
||||
|
||||
fn update_target_path() -> std::path::PathBuf {
|
||||
crate::config::config_path()
|
||||
.parent()
|
||||
.expect("config dir has parent")
|
||||
.join(".update_target")
|
||||
}
|
||||
|
||||
/// Write the expected version to disk before exec'ing the new binary.
|
||||
pub fn write_update_target(new_version: &str) {
|
||||
let _ = std::fs::write(update_target_path(), new_version);
|
||||
}
|
||||
|
||||
/// Read and delete the update-target file.
|
||||
/// Returns `Some(expected_version)` if a previous run attempted an update.
|
||||
/// The caller should compare it with `env!("CARGO_PKG_VERSION")` and show
|
||||
/// an error if they differ.
|
||||
pub fn take_update_target() -> Option<String> {
|
||||
let path = update_target_path();
|
||||
if !path.exists() {
|
||||
return None;
|
||||
}
|
||||
let version = std::fs::read_to_string(&path).ok()?;
|
||||
let _ = std::fs::remove_file(&path);
|
||||
Some(version.trim().to_string())
|
||||
}
|
||||
|
||||
/// Replaces current process via execv (Unix). Never returns on success.
|
||||
/// `exe_path` must be the path captured *before* the binary was replaced —
|
||||
/// do NOT call std::env::current_exe() here, it returns "(deleted)" on Linux.
|
||||
|
||||
Reference in New Issue
Block a user