From a9aa0ad736d8c7ed0a0fdd5a2c6486685760965c Mon Sep 17 00:00:00 2001 From: Uber Veng Date: Wed, 27 May 2026 23:06:12 +0700 Subject: [PATCH] Added proper version check before ask for update --- src/updater.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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.