Skip to content

Commit

Permalink
Merge pull request #47 from kpcyrd/select-least-outdated
Browse files Browse the repository at this point in the history
Fix bug if different versions are present for different architectures…
  • Loading branch information
kpcyrd authored Oct 31, 2024
2 parents 78a898e + 41d22eb commit ea21108
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct CacheEntry {
pub info: PkgInfo,
}

fn is_compatible(debversion: &str, crateversion: &VersionReq) -> Result<bool, Error> {
fn parse_deb_version(debversion: &str) -> Result<Version> {
let mut debversion = debversion.replace('~', "-");
if let Some((version, _suffix)) = debversion.split_once('+') {
debversion = match version.matches('.').count() {
Expand All @@ -40,7 +40,11 @@ fn is_compatible(debversion: &str, crateversion: &VersionReq) -> Result<bool, Er
};
}
let debversion = Version::parse(&debversion)?;
Ok(debversion)
}

fn is_compatible(debversion: &str, crateversion: &VersionReq) -> Result<bool, Error> {
let debversion = parse_deb_version(debversion)?;
Ok(crateversion.matches(&debversion))
}

Expand Down Expand Up @@ -205,6 +209,15 @@ impl Connection {
} else if info.status == PkgStatus::NotFound {
info.version = debversion.to_string();
info.status = PkgStatus::Outdated;
} else if info.status == PkgStatus::Outdated {
if let (Ok(existing), Ok(ours)) = (
parse_deb_version(&info.version),
parse_deb_version(debversion),
) {
if existing < ours {
info.version = debversion.to_string();
}
}
}
}

Expand Down

0 comments on commit ea21108

Please sign in to comment.