blob: dac0c2fd2dc347ca40c0b3ac77509953887d28f5 (
plain) (
tree)
|
|
use std::process::{Command, Stdio};
use crate::error::Error;
use super::{Package, PackageList, PackageManager};
pub struct Portage;
impl PackageManager for Portage {
fn get_installed(&self) -> crate::error::Result<PackageList> {
let eix_pkgs = Command::new("eix")
.args(["--world", "-c*"])
.output()
.unwrap();
let eix_pkgs_out = String::from_utf8(eix_pkgs.stdout).unwrap();
let mut pkgs: Vec<Package> = Vec::new();
let portage_pkgs: Vec<&str> = eix_pkgs_out.split('\n').collect();
for pkg in portage_pkgs {
if pkg.is_empty() {
continue;
};
let split = pkg.split_once('@');
let info = if let Some(sp) = split {
sp.0
} else {
return Err(Error::UnknownOutput);
};
let (id, version) = if let Some(res) = info.split_once('(') {
(res.0.split_at(4).1.trim().to_string(), res.1.to_string())
} else {
return Err(Error::UnknownOutput);
};
pkgs.push(Package {
id,
version,
explicit: true,
});
}
Ok(PackageList {
packages: pkgs,
manager: super::Manager::Portage,
})
}
fn install(&self, pkgs: Vec<super::Package>) -> crate::error::Result<()> {
let mut args = vec!["emerge".to_string()];
for pkg in pkgs {
args.push(pkg.id);
}
Command::new("doas")
.stdout(Stdio::inherit())
.args(args)
.spawn()?
.wait_with_output()?;
Ok(())
}
}
|