94 lines
2.3 KiB
Rust
94 lines
2.3 KiB
Rust
use crate::{PRIVLAGE_ESCELATE_COMMAND, error::Result, world::Packages};
|
|
use std::process::{Command, Stdio};
|
|
|
|
pub fn get_system_state() -> Result<Packages> {
|
|
let command = Command::new("pacman")
|
|
.arg("-Qqen")
|
|
.stdout(Stdio::piped())
|
|
.output()?;
|
|
|
|
let official: Vec<String> = String::from_utf8(command.stdout)?
|
|
.split_whitespace()
|
|
.map(|x| x.to_owned())
|
|
.collect();
|
|
|
|
let command = Command::new("pacman")
|
|
.arg("-Qqem")
|
|
.stdout(Stdio::piped())
|
|
.output()?;
|
|
|
|
let foreign: Vec<String> = String::from_utf8(command.stdout)?
|
|
.split_whitespace()
|
|
.map(|x| x.to_owned())
|
|
.collect();
|
|
|
|
Ok(Packages {
|
|
official,
|
|
foreign,
|
|
ignore: Vec::new(),
|
|
})
|
|
}
|
|
|
|
pub fn get_unneeded_packages() -> Result<Vec<String>> {
|
|
let command = Command::new("pacman")
|
|
.arg("-Qqdt")
|
|
.stdout(Stdio::piped())
|
|
.output()?;
|
|
|
|
let packages: Vec<String> = String::from_utf8(command.stdout)?
|
|
.split_whitespace()
|
|
.map(|x| x.to_owned())
|
|
.collect();
|
|
|
|
Ok(packages)
|
|
}
|
|
|
|
pub fn remove_packages(packages: &[String], all: bool) -> Result<()> {
|
|
let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND);
|
|
command.arg("pacman");
|
|
|
|
if all {
|
|
command.arg("-Rns");
|
|
} else {
|
|
command.arg("-Rs");
|
|
}
|
|
|
|
command
|
|
.args(packages)
|
|
.stdin(Stdio::inherit())
|
|
.stdout(Stdio::inherit())
|
|
.stderr(Stdio::inherit())
|
|
.status()?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn _update_packages(command: Command, packages: &[String]) -> Result<()> {
|
|
let mut command = command;
|
|
command
|
|
.arg("-Syu")
|
|
.args(packages)
|
|
.stderr(Stdio::inherit())
|
|
.stdout(Stdio::inherit())
|
|
.stdin(Stdio::inherit())
|
|
.status()?;
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(not(any(feature = "yay", feature = "paru")))]
|
|
pub fn update_packages(packages: &[String]) -> Result<()> {
|
|
let mut command = Command::new(PRIVLAGE_ESCELATE_COMMAND);
|
|
command.arg("pacman");
|
|
_update_packages(command, packages)
|
|
}
|
|
|
|
#[cfg(feature = "yay")]
|
|
pub fn update_packages(packages: &[String]) -> Result<()> {
|
|
_update_packages(Command::new("yay"), packages)
|
|
}
|
|
|
|
#[cfg(feature = "paru")]
|
|
pub fn update_packages(packages: &[String]) -> Result<()> {
|
|
_update_packages(Command::new("paru"), packages)
|
|
}
|