• 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/cellar.rs
1
use crate::config::Config;
2
use crate::types::{Installation, Package, PackageReq};
3
use libsemverator::semver::Semver as Version;
4
use std::error::Error;
5
use std::path::PathBuf;
6
use tokio::fs;
7

NEW
8
pub async fn ls(project: &str, config: &Config) -> Result<Vec<Installation>, Box<dyn Error>> {
×
NEW
9
    let d = config.pkgx_dir.join(project);
×
10

NEW
11
    if !fs::metadata(&d).await?.is_dir() {
×
NEW
12
        return Ok(vec![]);
×
13
    }
14

NEW
15
    let mut rv = vec![];
×
NEW
16
    let mut entries = fs::read_dir(&d).await?;
×
NEW
17
    while let Some(entry) = entries.next_entry().await? {
×
NEW
18
        let path = entry.path();
×
NEW
19
        let name = entry.file_name().to_string_lossy().to_string();
×
20

NEW
21
        if !name.starts_with('v') || name == "var" {
×
22
            continue;
23
        }
NEW
24
        if !fs::symlink_metadata(&path).await?.is_dir() {
×
25
            continue;
26
        }
27

NEW
28
        if let Ok(version) = Version::parse(&name[1..]) {
×
NEW
29
            rv.push(Installation {
×
NEW
30
                path,
×
NEW
31
                pkg: Package {
×
NEW
32
                    project: project.to_string(),
×
NEW
33
                    version,
×
34
                },
35
            });
36
        }
37
    }
38

NEW
39
    Ok(rv)
×
40
}
41

NEW
42
pub async fn resolve(pkgreq: &PackageReq, config: &Config) -> Result<Installation, Box<dyn Error>> {
×
NEW
43
    let installations = ls(&pkgreq.project, config).await?;
×
44

NEW
45
    if let Some(i) = installations
×
46
        .iter()
NEW
47
        .filter(|i| pkgreq.constraint.satisfies(&i.pkg.version))
×
NEW
48
        .max_by_key(|i| i.pkg.version.clone())
×
49
    {
NEW
50
        Ok(i.clone())
×
51
    } else {
52
        // If no matching version is found, return an error
NEW
53
        Err(format!("couldn’t resolve {:?}", pkgreq).into())
×
54
    }
55
}
56

NEW
57
pub async fn has(pkg: &PackageReq, config: &Config) -> Option<Installation> {
×
NEW
58
    resolve(pkg, config).await.ok()
×
59
}
60

NEW
61
pub fn dst(pkg: &Package, config: &Config) -> PathBuf {
×
NEW
62
    config
×
63
        .pkgx_dir
NEW
64
        .join(pkg.project.clone())
×
NEW
65
        .join(format!("v{}", pkg.version.raw))
×
66
}
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