resolve issues
This commit is contained in:
@@ -17,6 +17,7 @@ path-absolutize = "3.1"
|
||||
regex = { version = "1.10", default-features = false, features = ["std"] }
|
||||
termios = "0.3"
|
||||
walkdir = "2.5"
|
||||
libc = "0.2"
|
||||
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
@@ -29,12 +30,10 @@ pacdef_macros = { path = "../pacdef_macros", version = "1.0" }
|
||||
alpm = { version = "3.0", optional = true }
|
||||
rust-apt = { version = "0.7", optional = true }
|
||||
|
||||
libc = { version = "0.2", optional = true } # for debian
|
||||
|
||||
[dev-dependencies]
|
||||
rstest = "0.18"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
arch = ["dep:alpm"]
|
||||
debian = ["dep:rust-apt", "dep:libc"]
|
||||
debian = ["dep:rust-apt"]
|
||||
|
||||
@@ -8,6 +8,7 @@ use rust_apt::new_cache;
|
||||
|
||||
use crate::backend::backend_trait::{Backend, Switches, Text};
|
||||
use crate::backend::macros::impl_backend_constants;
|
||||
use crate::backend::root::build_base_command_with_privileges;
|
||||
use crate::{Group, Package};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -104,19 +105,3 @@ impl Debian {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn we_are_root() -> bool {
|
||||
let uid = unsafe { libc::geteuid() };
|
||||
uid == 0
|
||||
}
|
||||
|
||||
fn build_base_command_with_privileges(binary: &str) -> Command {
|
||||
let cmd = if we_are_root() {
|
||||
Command::new(binary)
|
||||
} else {
|
||||
let mut cmd = Command::new("sudo");
|
||||
cmd.arg(binary);
|
||||
cmd
|
||||
};
|
||||
cmd
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use regex::Regex;
|
||||
|
||||
use crate::backend::backend_trait::{Backend, Switches, Text};
|
||||
use crate::backend::macros::impl_backend_constants;
|
||||
use crate::backend::root::build_base_command_with_privileges;
|
||||
use crate::{Group, Package};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -42,12 +43,12 @@ impl Backend for Void {
|
||||
cmd.args(["-l"]);
|
||||
let output = String::from_utf8(cmd.output()?.stdout)?;
|
||||
|
||||
let packages: HashSet<Package> = output
|
||||
let packages = output
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let result = re1.replace_all(line, "").to_string();
|
||||
let result = re2.replace_all(&result, "").to_string();
|
||||
result.into()
|
||||
let result = re1.replace_all(line, "");
|
||||
let result = re2.replace_all(&result, "");
|
||||
result.to_string().into()
|
||||
})
|
||||
.collect();
|
||||
Ok(packages)
|
||||
@@ -61,7 +62,7 @@ impl Backend for Void {
|
||||
cmd.args(["-m"]);
|
||||
let output = String::from_utf8(cmd.output()?.stdout)?;
|
||||
|
||||
let packages: HashSet<Package> = output
|
||||
let packages = output
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let result = re.replace_all(line, "").to_string();
|
||||
@@ -73,8 +74,7 @@ impl Backend for Void {
|
||||
|
||||
/// Install the specified packages.
|
||||
fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result<ExitStatus> {
|
||||
let mut cmd = Command::new("sudo");
|
||||
cmd.arg(INSTALL_BINARY);
|
||||
let mut cmd = build_base_command_with_privileges(INSTALL_BINARY);
|
||||
cmd.args(self.get_switches_install());
|
||||
|
||||
if noconfirm {
|
||||
@@ -90,8 +90,7 @@ impl Backend for Void {
|
||||
}
|
||||
|
||||
fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result<ExitStatus> {
|
||||
let mut cmd = Command::new("sudo");
|
||||
cmd.arg(REMOVE_BINARY);
|
||||
let mut cmd = build_base_command_with_privileges(REMOVE_BINARY);
|
||||
cmd.args(self.get_switches_remove());
|
||||
|
||||
if noconfirm {
|
||||
@@ -107,8 +106,7 @@ impl Backend for Void {
|
||||
}
|
||||
|
||||
fn make_dependency(&self, packages: &[Package]) -> Result<ExitStatus> {
|
||||
let mut cmd = Command::new("sudo");
|
||||
cmd.arg(PKGDB_BINARY);
|
||||
let mut cmd = build_base_command_with_privileges(PKGDB_BINARY);
|
||||
cmd.args(self.get_switches_make_dependency());
|
||||
|
||||
for p in packages {
|
||||
|
||||
@@ -2,6 +2,7 @@ mod actual;
|
||||
mod backend_trait;
|
||||
mod iter;
|
||||
mod macros;
|
||||
mod root;
|
||||
mod todo_per_backend;
|
||||
|
||||
pub use backend_trait::Backend;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
use std::process::Command;
|
||||
|
||||
pub fn we_are_root() -> bool {
|
||||
let uid = unsafe { libc::geteuid() };
|
||||
uid == 0
|
||||
}
|
||||
|
||||
pub fn build_base_command_with_privileges(binary: &str) -> Command {
|
||||
let cmd = if we_are_root() {
|
||||
Command::new(binary)
|
||||
} else {
|
||||
let mut cmd = Command::new("sudo");
|
||||
cmd.arg(binary);
|
||||
cmd
|
||||
};
|
||||
cmd
|
||||
}
|
||||
Reference in New Issue
Block a user