Fixed version comparison when going above 0.9

This commit is contained in:
veeso
2022-08-30 15:54:37 +02:00
parent 2f1b644a40
commit 833cd7d3ba
4 changed files with 26 additions and 1 deletions
+2
View File
@@ -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)) - **Yes/No dialogs** are now answerable by pressing `Y` or `N` on your keyboard ([Issue 121](https://github.com/veeso/termscp/issues/121))
- **Bugfix** - **Bugfix**
- Fixed [Issue 122](https://github.com/veeso/termscp/issues/122) - Fixed [Issue 122](https://github.com/veeso/termscp/issues/122)
- Fixed version comparison when going above 0.9
- Dependencies: - Dependencies:
- Bump `argh` to `0.1.8` - Bump `argh` to `0.1.8`
- Bump `chrono` to `0.4.22` - Bump `chrono` to `0.4.22`
@@ -45,6 +46,7 @@ Released on ??
- Changed `regex` to `lazy-regex 2.3.0` - Changed `regex` to `lazy-regex 2.3.0`
- Bump `tuirealm` to `1.8.0` - Bump `tuirealm` to `1.8.0`
- Bump `tui-realm-stdlib` to `1.1.7` - Bump `tui-realm-stdlib` to `1.1.7`
- Added `version-compare 0.1.0`
- Bump `wildmatch` to `2.1.1` - Bump `wildmatch` to `2.1.1`
## 0.9.0 ## 0.9.0
Generated
+7
View File
@@ -2518,6 +2518,7 @@ dependencies = [
"tuirealm", "tuirealm",
"unicode-width", "unicode-width",
"users", "users",
"version-compare",
"whoami", "whoami",
"wildmatch", "wildmatch",
] ]
@@ -2827,6 +2828,12 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version-compare"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
+1
View File
@@ -62,6 +62,7 @@ toml = "0.5.0"
tui-realm-stdlib = "1.1.7" tui-realm-stdlib = "1.1.7"
tuirealm = "1.8.0" tuirealm = "1.8.0"
unicode-width = "0.1.8" unicode-width = "0.1.8"
version-compare = "0.1.0"
whoami = "1.2.1" whoami = "1.2.1"
wildmatch = "2.1.1" wildmatch = "2.1.1"
+16 -1
View File
@@ -96,7 +96,7 @@ impl Update {
new_version, new_version,
cargo_crate_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 Some(r) // New version is available
} else { } else {
None // No new version None // No new version
@@ -105,6 +105,12 @@ impl Update {
None => None, 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<Status> for UpdateStatus { impl From<Status> for UpdateStatus {
fn from(s: Status) -> Self { fn from(s: Status) -> Self {
@@ -193,4 +199,13 @@ mod test {
assert_eq!(release.body.as_str(), "fixed everything"); assert_eq!(release.body.as_str(), "fixed everything");
assert_eq!(release.version.as_str(), "0.7.0"); 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"));
}
} }