archlinux_inputs_fsck/
asp.rs

1use crate::errors::*;
2use std::path::{Path, PathBuf};
3use std::process::Stdio;
4use tokio::process::Command;
5
6pub async fn list_packages() -> Result<Vec<String>> {
7    let cmd = Command::new("asp")
8        .arg("list-all")
9        .stdout(Stdio::piped())
10        .spawn()
11        .context("Failed to run asp list-all")?;
12
13    let out = cmd.wait_with_output().await?;
14    if !out.status.success() {
15        bail!("Process (asp list-all) exited with error: {:?}", out.status);
16    }
17
18    let buf = String::from_utf8(out.stdout).context("List of packages contains invalid utf8")?;
19    Ok(buf.lines().map(String::from).collect())
20}
21
22pub async fn checkout_package(pkgbase: &str, directory: &Path) -> Result<PathBuf> {
23    debug!("Checkout out {:?} to {:?}", pkgbase, directory);
24    let cmd = Command::new("asp")
25        .args(&["checkout", pkgbase])
26        // TODO: find a better way to make it silent without discarding stderr
27        .stderr(Stdio::null())
28        .current_dir(directory)
29        .spawn()
30        .with_context(|| anyhow!("Failed to run asp checkout {:?}", pkgbase))?;
31
32    let out = cmd.wait_with_output().await?;
33    if !out.status.success() {
34        bail!(
35            "Process (asp checkout {:?}) exited with error: {:?}",
36            pkgbase,
37            out.status
38        );
39    }
40
41    Ok(directory.join(pkgbase))
42}