Skip to content

Commit

Permalink
db: relax version checking
Browse files Browse the repository at this point in the history
When calling `search_generic()`, the `version` parameter is taken from
the output of `cargo metadata`, which always return the latest version
available on crates.io. Due to ba11751 this implies the crate will be
considered missing from Debian unless the packaged version is the latest
one.

This commit adds a fallback version check in case the initial check
fails, by trimming the version to a supposedly compatible semver
version.

Fixes #31
  • Loading branch information
a-wai committed Nov 2, 2023
1 parent 956c9ab commit 57937da
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,26 @@ impl Connection {
version: &Version,
) -> Result<bool, Error> {
let package = package.replace('_', "-");
let semver_package = if version.major == 0 {
format!("rust-{package}-{}.{}", version.major, version.minor)
let semver_version = if version.major == 0 {
if version.minor == 0 {
format!("{}.{}.{}", version.major, version.minor, version.patch)
} else {
format!("{}.{}", version.major, version.minor)
}
} else {
format!("rust-{package}-{}", version.major)
format!("{}", version.major)
};
let rows = self
.sock
.query(query, &[&format!("rust-{package}"), &semver_package])?;
let rows = self.sock.query(
query,
&[
&format!("rust-{package}"),
&format!("rust-{package}-{}", semver_version),
],
)?;

let version = version.to_string();
let version = VersionReq::parse(&version)?;
let semver_version = VersionReq::parse(&semver_version)?;
for row in &rows {
let debversion: String = row.get(0);

Expand All @@ -151,7 +160,7 @@ impl Connection {

// println!("{:?} ({:?}) => {:?}", debversion, version, is_compatible(debversion, version)?);

if is_compatible(debversion, &version)? {
if is_compatible(debversion, &version)? || is_compatible(debversion, &semver_version)? {
return Ok(true);
}
}
Expand Down

0 comments on commit 57937da

Please sign in to comment.