diff --git a/src/updater.rs b/src/updater.rs index a1a355b..a74f9d5 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -61,8 +61,8 @@ pub async fn check(api_base: &str, timeout_sec: u64) -> Result Option { 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::().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. /// `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.