Skip to content

Commit

Permalink
compare library versions
Browse files Browse the repository at this point in the history
  • Loading branch information
blarfoon committed Nov 2, 2024
1 parent 3b9d389 commit a5c63f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions daedalus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sha1 = { version = "0.6.1", features = ["std"] }
bincode = { version = "2.0.0-rc.3", features = ["serde"], optional = true }
once_cell = "1"
url = "2"
lenient_semver = "0"

[build-dependencies]
dotenvy = "0.15.6"
21 changes: 20 additions & 1 deletion daedalus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#![warn(missing_docs, unused_import_braces, missing_debug_implementations)]

use std::{
convert::TryFrom, fmt::Display, path::PathBuf, str::FromStr, time::Duration,
cmp::Ordering, convert::TryFrom, fmt::Display, path::PathBuf, str::FromStr,
time::Duration,
};

use backon::{ExponentialBuilder, Retryable};
Expand Down Expand Up @@ -178,6 +179,24 @@ impl GradleSpecifier {
pub fn is_log4j(&self) -> bool {
self.package.as_str() == "org.apache.logging.log4j"
}

/// Compares two versions
/// Returns Ordering::Equal if they are equal
/// Returns Ordering::Greater if self is greater than other
/// Returns Ordering::Less if self is less than other
pub fn compare_versions(&self, other: &Self) -> Result<Ordering, Error> {
let x = lenient_semver::parse(self.version.as_str());
let y = lenient_semver::parse(other.version.as_str());

if x.is_err() || y.is_err() {
return Err(Error::ParseError(
"Unable to parse version".to_string(),
));
}

// safe to unwrap because we already checked for errors
Ok(x.unwrap().cmp(&y.unwrap()))
}
}

impl FromStr for GradleSpecifier {
Expand Down

0 comments on commit a5c63f8

Please sign in to comment.