Added proper version check before ask for update
This commit is contained in:
@@ -61,8 +61,8 @@ pub async fn check(api_base: &str, timeout_sec: u64) -> Result<Option<UpdateInfo
|
|||||||
let tag = tag.split('@').next().unwrap_or(tag).trim();
|
let tag = tag.split('@').next().unwrap_or(tag).trim();
|
||||||
let new_version = tag.to_string();
|
let new_version = tag.to_string();
|
||||||
|
|
||||||
// Already up to date
|
// Only offer update if the remote version is strictly newer
|
||||||
if new_version == current_version {
|
if !is_newer(&new_version, ¤t_version) {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +185,16 @@ pub fn take_update_target() -> Option<String> {
|
|||||||
Some(version.trim().to_string())
|
Some(version.trim().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if `candidate` is strictly greater than `current` by semver rules.
|
||||||
|
/// Parses `MAJOR.MINOR.PATCH`; any unparseable component is treated as 0.
|
||||||
|
fn is_newer(candidate: &str, current: &str) -> bool {
|
||||||
|
fn parse(v: &str) -> (u64, u64, u64) {
|
||||||
|
let mut parts = v.splitn(3, '.').map(|s| s.parse::<u64>().unwrap_or(0));
|
||||||
|
(parts.next().unwrap_or(0), parts.next().unwrap_or(0), parts.next().unwrap_or(0))
|
||||||
|
}
|
||||||
|
parse(candidate) > parse(current)
|
||||||
|
}
|
||||||
|
|
||||||
/// Replaces current process via execv (Unix). Never returns on success.
|
/// Replaces current process via execv (Unix). Never returns on success.
|
||||||
/// `exe_path` must be the path captured *before* the binary was replaced —
|
/// `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.
|
/// do NOT call std::env::current_exe() here, it returns "(deleted)" on Linux.
|
||||||
|
|||||||
Reference in New Issue
Block a user