• 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/sync.rs
1
use crate::{config::Config, pantry_db};
2
use async_compression::tokio::bufread::GzipDecoder;
3
use fs2::FileExt;
4
use futures::TryStreamExt;
5
use rusqlite::Connection;
6
use std::{error::Error, fs::OpenOptions, path::PathBuf};
7
use tokio_tar::Archive;
8
use tokio_util::compat::FuturesAsyncReadCompatExt;
9

10
#[allow(clippy::all)]
NEW
11
pub fn should(config: &Config) -> bool {
×
NEW
12
    if !config.pantry_dir.join("projects").is_dir() {
×
NEW
13
        true
×
NEW
14
    } else if !config
×
15
        .pantry_dir
16
        .parent()
17
        .unwrap()
18
        .join("pantry.db")
NEW
19
        .is_file()
×
20
    {
NEW
21
        true
×
22
    } else {
NEW
23
        false
×
24
    }
25
}
26

NEW
27
pub async fn replace(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error>> {
×
NEW
28
    let url = env!("PKGX_PANTRY_TARBALL_URL");
×
NEW
29
    let dest = &config.pantry_dir;
×
30

NEW
31
    std::fs::create_dir_all(dest.clone())?;
×
NEW
32
    let dir = OpenOptions::new()
×
33
        .read(true) // Open in read-only mode; no need to write.
NEW
34
        .open(dest)?;
×
NEW
35
    dir.lock_exclusive()?;
×
36

NEW
37
    download_and_extract_pantry(url, dest).await?;
×
38

NEW
39
    pantry_db::cache(config, conn)?;
×
40

NEW
41
    FileExt::unlock(&dir)?;
×
42

NEW
43
    Ok(())
×
44
}
45

NEW
46
async fn download_and_extract_pantry(url: &str, dest: &PathBuf) -> Result<(), Box<dyn Error>> {
×
NEW
47
    let rsp = reqwest::get(url).await?.error_for_status()?;
×
48

NEW
49
    let stream = rsp.bytes_stream();
×
50

NEW
51
    let stream = stream
×
NEW
52
        .map_err(|e| futures::io::Error::new(futures::io::ErrorKind::Other, e))
×
53
        .into_async_read();
NEW
54
    let stream = stream.compat();
×
55

NEW
56
    let decoder = GzipDecoder::new(stream);
×
57

58
    // Step 3: Extract the tar archive
NEW
59
    let mut archive = Archive::new(decoder);
×
NEW
60
    archive.unpack(dest).await?;
×
61

NEW
62
    Ok(())
×
63
}
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