• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkgxdev / pkgx / 12768583963

14 Jan 2025 01:23PM UTC coverage: 1.643% (-90.3%) from 91.907%
12768583963

Pull #1068

github

web-flow
Merge aab1de74e into 6a195bfb8
Pull Request #1068: v2

13 of 791 new or added lines in 17 files covered. (1.64%)

13 of 791 relevant lines covered (1.64%)

0.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/lib/src/inventory.rs
1
use crate::config::Config;
2
use crate::types::{host, Package, PackageReq};
3
use libsemverator::semver::Semver as Version;
4
use reqwest::Url;
5
use std::error::Error;
6

7
// Custom error for download issues
8
#[derive(Debug)]
9
pub struct DownloadError {
10
    pub status: u16,
11
    pub src: String,
12
}
13

14
impl std::fmt::Display for DownloadError {
NEW
15
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
NEW
16
        write!(
×
17
            f,
18
            "Download error: status code {} from {}",
19
            self.status, self.src
20
        )
21
    }
22
}
23

24
impl Error for DownloadError {}
25

26
// Select function to pick a version
NEW
27
pub async fn select(rq: &PackageReq, config: &Config) -> Result<Option<Version>, Box<dyn Error>> {
×
NEW
28
    let versions = ls(rq, config).await?;
×
29

NEW
30
    Ok(versions
×
31
        .iter()
NEW
32
        .filter(|v| rq.constraint.satisfies(v))
×
33
        .max()
34
        .cloned())
35
}
36

37
// Get function to fetch available versions
NEW
38
pub async fn ls(rq: &PackageReq, config: &Config) -> Result<Vec<Version>, Box<dyn Error>> {
×
NEW
39
    let base_url = config.dist_url.clone();
×
40

NEW
41
    let (platform, arch) = host();
×
NEW
42
    let url = Url::parse(&format!(
×
43
        "{}/{}/{}/{}/versions.txt",
44
        base_url, rq.project, platform, arch
45
    ))?;
46

NEW
47
    let rsp = reqwest::get(url.clone()).await?;
×
48

NEW
49
    if !rsp.status().is_success() {
×
NEW
50
        return Err(Box::new(DownloadError {
×
NEW
51
            status: rsp.status().as_u16(),
×
NEW
52
            src: url.to_string(),
×
53
        }));
54
    }
55

NEW
56
    let releases = rsp.text().await?;
×
NEW
57
    let mut versions: Vec<Version> = releases
×
58
        .lines()
59
        .map(Version::parse)
60
        .filter_map(Result::ok)
61
        .collect();
62

NEW
63
    if versions.is_empty() {
×
NEW
64
        return Err(Box::new(std::io::Error::new(
×
NEW
65
            std::io::ErrorKind::Other,
×
NEW
66
            format!("No versions for {}", rq.project),
×
67
        )));
68
    }
69

NEW
70
    if rq.project == "openssl.org" {
×
71
        // Workaround: Remove specific version
NEW
72
        let excluded_version = Version::parse("1.1.118")?;
×
NEW
73
        versions.retain(|x| x != &excluded_version);
×
74
    }
75

NEW
76
    Ok(versions)
×
77
}
78

79
//TODO xz bottles are preferred
NEW
80
pub fn get_url(pkg: &Package, config: &Config) -> String {
×
NEW
81
    let (platform, arch) = host();
×
NEW
82
    format!(
×
83
        "{}/{}/{}/{}/v{}.tar.xz",
84
        config.dist_url, pkg.project, platform, arch, pkg.version.raw
85
    )
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc