complete Pacman backend
This commit is contained in:
+28
-2
@@ -1,6 +1,8 @@
|
||||
mod pacman;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::Package;
|
||||
|
||||
@@ -9,12 +11,36 @@ pub use pacman::Pacman;
|
||||
pub trait Backend {
|
||||
/// The binary that should be called to run the associated package manager.
|
||||
const BINARY: &'static str;
|
||||
|
||||
/// The switches that signals the `BINARY` that the packages should be installed.
|
||||
const SWITCH_INSTALL: &'static str;
|
||||
|
||||
/// The switches that signals the `BINARY` that the packages should be removed.
|
||||
const SWITCH_REMOVE: &'static str;
|
||||
|
||||
/// Get all packages that are installed in the system.
|
||||
fn get_all_installed_packages() -> HashSet<Package>;
|
||||
|
||||
/// Get all packages that were installed in the system explicitly.
|
||||
fn get_explicitly_installed_packages() -> HashSet<Package>;
|
||||
|
||||
/// Install the specified packages.
|
||||
fn install_packages(packages: Vec<Package>);
|
||||
fn install_packages(packages: Vec<Package>) {
|
||||
let mut cmd = Command::new(Self::BINARY);
|
||||
cmd.arg(Self::SWITCH_INSTALL);
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.exec();
|
||||
}
|
||||
|
||||
/// Remove the specified packages.
|
||||
fn remove_packages(packages: Vec<Package>);
|
||||
fn remove_packages(packages: Vec<Package>) {
|
||||
let mut cmd = Command::new(Self::BINARY);
|
||||
cmd.arg(Self::SWITCH_REMOVE);
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.exec();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-20
@@ -1,6 +1,4 @@
|
||||
use std::collections::HashSet;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::Command;
|
||||
|
||||
use alpm::Alpm;
|
||||
use alpm::PackageReason::Explicit;
|
||||
@@ -12,6 +10,8 @@ pub struct Pacman;
|
||||
|
||||
impl Backend for Pacman {
|
||||
const BINARY: &'static str = "paru";
|
||||
const SWITCH_INSTALL: &'static str = "-S";
|
||||
const SWITCH_REMOVE: &'static str = "-Rsn";
|
||||
|
||||
fn get_all_installed_packages() -> HashSet<Package> {
|
||||
convert_to_pacdef_packages(get_all_installed_packages_from_alpm())
|
||||
@@ -20,24 +20,6 @@ impl Backend for Pacman {
|
||||
fn get_explicitly_installed_packages() -> HashSet<Package> {
|
||||
convert_to_pacdef_packages(get_explicitly_installed_packages_from_alpm())
|
||||
}
|
||||
|
||||
fn install_packages(packages: Vec<Package>) {
|
||||
let mut cmd = Command::new("paru");
|
||||
cmd.arg("-S");
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.exec();
|
||||
}
|
||||
|
||||
fn remove_packages(packages: Vec<Package>) {
|
||||
let mut cmd = Command::new("paru");
|
||||
cmd.arg("-Rsn");
|
||||
for p in packages {
|
||||
cmd.arg(format!("{p}"));
|
||||
}
|
||||
cmd.exec();
|
||||
}
|
||||
}
|
||||
|
||||
fn get_all_installed_packages_from_alpm() -> HashSet<String> {
|
||||
|
||||
Reference in New Issue
Block a user