diff --git a/CHANGELOG.md b/CHANGELOG.md index 637ad22..864d73e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Released on ?? - **Yes/No dialogs** are now answerable by pressing `Y` or `N` on your keyboard ([Issue 121](https://github.com/veeso/termscp/issues/121)) - **Bugfix** - Fixed [Issue 122](https://github.com/veeso/termscp/issues/122) + - Fixed version comparison when going above 0.9 - Dependencies: - Bump `argh` to `0.1.8` - Bump `chrono` to `0.4.22` @@ -45,6 +46,7 @@ Released on ?? - Changed `regex` to `lazy-regex 2.3.0` - Bump `tuirealm` to `1.8.0` - Bump `tui-realm-stdlib` to `1.1.7` + - Added `version-compare 0.1.0` - Bump `wildmatch` to `2.1.1` ## 0.9.0 diff --git a/Cargo.lock b/Cargo.lock index 7569980..2fe8286 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2518,6 +2518,7 @@ dependencies = [ "tuirealm", "unicode-width", "users", + "version-compare", "whoami", "wildmatch", ] @@ -2827,6 +2828,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version-compare" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index ca1f581..919db11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ toml = "0.5.0" tui-realm-stdlib = "1.1.7" tuirealm = "1.8.0" unicode-width = "0.1.8" +version-compare = "0.1.0" whoami = "1.2.1" wildmatch = "2.1.1" diff --git a/src/system/auto_update.rs b/src/system/auto_update.rs index 172ef41..12eab46 100644 --- a/src/system/auto_update.rs +++ b/src/system/auto_update.rs @@ -96,7 +96,7 @@ impl Update { new_version, cargo_crate_version!() ); - if new_version.as_str() > cargo_crate_version!() { + if Self::is_new_version_higher(new_version.as_str(), cargo_crate_version!()) { Some(r) // New version is available } else { None // No new version @@ -105,6 +105,12 @@ impl Update { None => None, } } + + /// Check wether new version is higher than new version + fn is_new_version_higher(new_version: &str, current_version: &str) -> bool { + version_compare::compare(new_version, current_version).unwrap_or(version_compare::Cmp::Lt) + == version_compare::Cmp::Gt + } } impl From for UpdateStatus { fn from(s: Status) -> Self { @@ -193,4 +199,13 @@ mod test { assert_eq!(release.body.as_str(), "fixed everything"); assert_eq!(release.version.as_str(), "0.7.0"); } + + #[test] + fn should_tell_that_version_is_higher() { + assert!(Update::is_new_version_higher("0.10.0", "0.9.0")); + assert!(Update::is_new_version_higher("0.20.0", "0.19.0")); + assert!(!Update::is_new_version_higher("0.9.0", "0.10.0")); + assert!(!Update::is_new_version_higher("0.9.9", "0.10.1")); + assert!(!Update::is_new_version_higher("0.10.9", "0.11.0")); + } }