From f947b8e56a65c55b264c8000f06853f5f9faae85 Mon Sep 17 00:00:00 2001 From: Book-reader Date: Thu, 4 Apr 2024 17:34:46 +1300 Subject: [PATCH 1/7] add void backend --- .vscode/settings.json | 7 + Cargo.toml | 1 + crates/pacdef_core/Cargo.toml | 1 + crates/pacdef_core/src/backend/actual/mod.rs | 2 + crates/pacdef_core/src/backend/actual/void.rs | 144 ++++++++++++++++++ crates/pacdef_core/src/backend/mod.rs | 2 + 6 files changed, 157 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 crates/pacdef_core/src/backend/actual/void.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ccfdd49 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "rust-analyzer.linkedProjects": [ + "./crates/pacdef_core/Cargo.toml", + "./crates/pacdef_core/Cargo.toml", + "./crates/pacdef_core/Cargo.toml" + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index d265fbd..54a24f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,4 @@ strip = true default = [] debian = ["pacdef_core/debian"] arch = ["pacdef_core/arch"] +void = ["pacdef_core/void"] diff --git a/crates/pacdef_core/Cargo.toml b/crates/pacdef_core/Cargo.toml index 802d8fa..79fff2a 100644 --- a/crates/pacdef_core/Cargo.toml +++ b/crates/pacdef_core/Cargo.toml @@ -38,3 +38,4 @@ rstest = "0.18" default = [] arch = ["dep:alpm"] debian = ["dep:rust-apt", "dep:libc"] +void = [] diff --git a/crates/pacdef_core/src/backend/actual/mod.rs b/crates/pacdef_core/src/backend/actual/mod.rs index 36ad67e..07b1c59 100644 --- a/crates/pacdef_core/src/backend/actual/mod.rs +++ b/crates/pacdef_core/src/backend/actual/mod.rs @@ -2,6 +2,8 @@ pub mod arch; #[cfg(feature = "debian")] pub mod debian; +#[cfg(feature = "void")] +pub mod void; pub mod flatpak; pub mod python; pub mod rust; diff --git a/crates/pacdef_core/src/backend/actual/void.rs b/crates/pacdef_core/src/backend/actual/void.rs new file mode 100644 index 0000000..abc6f92 --- /dev/null +++ b/crates/pacdef_core/src/backend/actual/void.rs @@ -0,0 +1,144 @@ +use core::panic; +use std::collections::HashSet; +use std::process::{Command, ExitStatus}; + +use anyhow::{Context, Result}; +use regex::Regex; + +use crate::backend::backend_trait::{Backend, Switches, Text}; +use crate::backend::macros::impl_backend_constants; +use crate::{Group, Package}; + +#[derive(Debug, Clone)] +pub struct Void { + pub(crate) packages: HashSet, +} + +const BINARY: Text = "xbps-install"; +const INSTALL_BINARY: Text = "xbps-install"; +const REMOVE_BINARY: Text = "xbps-remove"; +const QUERY_BINARY: Text = "xbps-query"; +const PKGDB_BINARY: Text = "xbps-pkgdb"; +const SECTION: Text = "void"; + +const SWITCHES_INFO: Switches = &["-m"]; +const SWITCHES_INSTALL: Switches = &["-S"]; +const SWITCHES_MAKE_DEPENDENCY: Switches = &["-m", "auto"]; +const SWITCHES_NOCONFIRM: Switches = &["-y"]; +const SWITCHES_REMOVE: Switches = &["-R"]; + +const SUPPORTS_AS_DEPENDENCY: bool = true; +impl Void { + fn get_binary_info(&self) -> Text { + QUERY_BINARY + } + + fn get_binary_install(&self) -> Text { + INSTALL_BINARY + } + + fn get_binary_remove(&self) -> Text { + REMOVE_BINARY + } + + fn get_binary_make_dependency(&self) -> Text { + PKGDB_BINARY + } +} + +impl Backend for Void { + impl_backend_constants!(); + + fn get_all_installed_packages(&self) -> Result> { + let re_str_1 = r"ii | .*"; + let re_str_2 = r"-[^-]*$"; + let re1 = Regex::new(re_str_1)?; + let re2 = Regex::new(re_str_2)?; + let mut cmd = Command::new(self.get_binary_info()); + cmd.args(&["-l"]); + let output = String::from_utf8(cmd.output()?.stdout)?; + + let packages: HashSet = output + .lines() + .map(|line| { + let result = re1.replace_all(line, "").to_string(); + let result = re2.replace_all(&result, "").to_string(); + result.into() + }) + .collect(); + Ok(packages) + } + + fn get_explicitly_installed_packages(&self) -> Result> { + let re_str = r"-[^-]*$"; + let re = Regex::new(re_str)?; + let mut cmd = Command::new(self.get_binary_info()); + cmd.args(self.get_switches_info()); + let output = String::from_utf8(cmd.output()?.stdout)?; + + let packages: HashSet = output + .lines() + .map(|line| { + let result = re.replace_all(line, "").to_string(); + result.into() + }) + .collect(); + Ok(packages) + } + + /// Install the specified packages. + fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { + let mut cmd = Command::new("sudo"); + cmd.arg(self.get_binary_install()); + cmd.args(self.get_switches_install()); + + if noconfirm { + cmd.args(self.get_switches_noconfirm()); + } + + for p in packages { + cmd.arg(format!("{p}")); + } + + cmd.status() + .with_context(|| format!("running command {cmd:?}")) + } + + fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { + let mut cmd = Command::new("sudo"); + cmd.arg(self.get_binary_remove()); + cmd.args(self.get_switches_remove()); + + if noconfirm { + cmd.args(self.get_switches_noconfirm()); + } + + for p in packages { + cmd.arg(format!("{p}")); + } + + cmd.status() + .with_context(|| format!("running command [{cmd:?}]")) + } + + fn make_dependency(&self, packages: &[Package]) -> Result { + let mut cmd = Command::new("sudo"); + cmd.arg(self.get_binary_make_dependency()); + cmd.args(self.get_switches_make_dependency()); + + for p in packages { + cmd.arg(format!("{p}")); + } + + cmd.status() + .with_context(|| format!("running command [{cmd:?}]")) + } +} + +impl Void { + pub fn new() -> Self { + Void { + packages: HashSet::new(), + } + } +} diff --git a/crates/pacdef_core/src/backend/mod.rs b/crates/pacdef_core/src/backend/mod.rs index 0664d7e..30215ac 100644 --- a/crates/pacdef_core/src/backend/mod.rs +++ b/crates/pacdef_core/src/backend/mod.rs @@ -16,6 +16,8 @@ pub enum Backends { Arch, #[cfg(feature = "debian")] Debian, + #[cfg(feature = "void")] + Void, Flatpak, Python, Rust, From 9a8949227f6d38a0bf2100f53d950a1691aae147 Mon Sep 17 00:00:00 2001 From: Book-reader Date: Thu, 4 Apr 2024 17:37:57 +1300 Subject: [PATCH 2/7] add void backend to readme --- .vscode/settings.json | 7 ------- README.md | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ccfdd49..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "rust-analyzer.linkedProjects": [ - "./crates/pacdef_core/Cargo.toml", - "./crates/pacdef_core/Cargo.toml", - "./crates/pacdef_core/Cargo.toml" - ] -} \ No newline at end of file diff --git a/README.md b/README.md index 0a7ee44..52bf387 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Pull requests for additional backends are welcome! | ----------- | --------------- | ----------- | ------------ | ---------------------------------------------------------------------------------------- | | Arch Linux | `pacman` | `[arch]` | `arch` | includes pacman-wrapping AUR helpers (configurable) | | Debian | `apt` | `[debian]` | `debian` | minimum supported apt-version 2.0.2 ([see upstream](https://gitlab.com/volian/rust-apt)) | +| Void Linux | `xbps` | `[void]` | `void` | | | Flatpak | `flatpak` | `[flatpak]` | built-in | can manage either system-wide or per-user installation (configurable) | | Python | `pip` | `[python]` | built-in | | | Rust | `cargo` | `[rust]` | built-in | | From cf64bb0f722573e5738fcc4260c3baf80e357fc9 Mon Sep 17 00:00:00 2001 From: Book-reader Date: Thu, 4 Apr 2024 18:59:06 +1300 Subject: [PATCH 3/7] improve regex and comment regex --- crates/pacdef_core/src/backend/actual/void.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/pacdef_core/src/backend/actual/void.rs b/crates/pacdef_core/src/backend/actual/void.rs index abc6f92..51e9091 100644 --- a/crates/pacdef_core/src/backend/actual/void.rs +++ b/crates/pacdef_core/src/backend/actual/void.rs @@ -50,7 +50,9 @@ impl Backend for Void { impl_backend_constants!(); fn get_all_installed_packages(&self) -> Result> { - let re_str_1 = r"ii | .*"; + // Removes the package status and description from output + let re_str_1 = r"^ii |^uu |^hr |^\?\? | .*"; + // Removes the package version from output let re_str_2 = r"-[^-]*$"; let re1 = Regex::new(re_str_1)?; let re2 = Regex::new(re_str_2)?; @@ -70,6 +72,7 @@ impl Backend for Void { } fn get_explicitly_installed_packages(&self) -> Result> { + // Removes the package version from output let re_str = r"-[^-]*$"; let re = Regex::new(re_str)?; let mut cmd = Command::new(self.get_binary_info()); From 1db032dd5cd5cb1b91dce6f7775aad6b6929bba5 Mon Sep 17 00:00:00 2001 From: Samuel Talbot Date: Thu, 4 Apr 2024 19:53:29 +1300 Subject: [PATCH 4/7] clippy and formatting --- Cargo.toml | 1 - README.md | 2 +- crates/pacdef_core/Cargo.toml | 1 - crates/pacdef_core/src/backend/actual/mod.rs | 3 +- crates/pacdef_core/src/backend/actual/void.rs | 34 +++++-------------- crates/pacdef_core/src/backend/mod.rs | 3 +- 6 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54a24f6..d265fbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,3 @@ strip = true default = [] debian = ["pacdef_core/debian"] arch = ["pacdef_core/arch"] -void = ["pacdef_core/void"] diff --git a/README.md b/README.md index 52bf387..4b8ce9e 100644 --- a/README.md +++ b/README.md @@ -88,11 +88,11 @@ Pull requests for additional backends are welcome! | ----------- | --------------- | ----------- | ------------ | ---------------------------------------------------------------------------------------- | | Arch Linux | `pacman` | `[arch]` | `arch` | includes pacman-wrapping AUR helpers (configurable) | | Debian | `apt` | `[debian]` | `debian` | minimum supported apt-version 2.0.2 ([see upstream](https://gitlab.com/volian/rust-apt)) | -| Void Linux | `xbps` | `[void]` | `void` | | | Flatpak | `flatpak` | `[flatpak]` | built-in | can manage either system-wide or per-user installation (configurable) | | Python | `pip` | `[python]` | built-in | | | Rust | `cargo` | `[rust]` | built-in | | | Rustup | `rustup` | `[rustup]` | built-in | See the comments [below](#rustup) about the syntax of the packages in the group file. | +| Void Linux | `xbps` | `[void]` | built-in | | Backends that have a `feature flag` require setting the respective flag for the build process. The appropriate system libraries and their header files must be present on the machine and be detectable by `pkg-config`. diff --git a/crates/pacdef_core/Cargo.toml b/crates/pacdef_core/Cargo.toml index 79fff2a..802d8fa 100644 --- a/crates/pacdef_core/Cargo.toml +++ b/crates/pacdef_core/Cargo.toml @@ -38,4 +38,3 @@ rstest = "0.18" default = [] arch = ["dep:alpm"] debian = ["dep:rust-apt", "dep:libc"] -void = [] diff --git a/crates/pacdef_core/src/backend/actual/mod.rs b/crates/pacdef_core/src/backend/actual/mod.rs index 07b1c59..ea93f66 100644 --- a/crates/pacdef_core/src/backend/actual/mod.rs +++ b/crates/pacdef_core/src/backend/actual/mod.rs @@ -2,9 +2,8 @@ pub mod arch; #[cfg(feature = "debian")] pub mod debian; -#[cfg(feature = "void")] -pub mod void; pub mod flatpak; pub mod python; pub mod rust; pub mod rustup; +pub mod void; diff --git a/crates/pacdef_core/src/backend/actual/void.rs b/crates/pacdef_core/src/backend/actual/void.rs index 51e9091..7177de5 100644 --- a/crates/pacdef_core/src/backend/actual/void.rs +++ b/crates/pacdef_core/src/backend/actual/void.rs @@ -1,4 +1,3 @@ -use core::panic; use std::collections::HashSet; use std::process::{Command, ExitStatus}; @@ -28,23 +27,6 @@ const SWITCHES_NOCONFIRM: Switches = &["-y"]; const SWITCHES_REMOVE: Switches = &["-R"]; const SUPPORTS_AS_DEPENDENCY: bool = true; -impl Void { - fn get_binary_info(&self) -> Text { - QUERY_BINARY - } - - fn get_binary_install(&self) -> Text { - INSTALL_BINARY - } - - fn get_binary_remove(&self) -> Text { - REMOVE_BINARY - } - - fn get_binary_make_dependency(&self) -> Text { - PKGDB_BINARY - } -} impl Backend for Void { impl_backend_constants!(); @@ -56,8 +38,8 @@ impl Backend for Void { let re_str_2 = r"-[^-]*$"; let re1 = Regex::new(re_str_1)?; let re2 = Regex::new(re_str_2)?; - let mut cmd = Command::new(self.get_binary_info()); - cmd.args(&["-l"]); + let mut cmd = Command::new(QUERY_BINARY); + cmd.args(["-l"]); let output = String::from_utf8(cmd.output()?.stdout)?; let packages: HashSet = output @@ -75,7 +57,7 @@ impl Backend for Void { // Removes the package version from output let re_str = r"-[^-]*$"; let re = Regex::new(re_str)?; - let mut cmd = Command::new(self.get_binary_info()); + let mut cmd = Command::new(QUERY_BINARY); cmd.args(self.get_switches_info()); let output = String::from_utf8(cmd.output()?.stdout)?; @@ -92,7 +74,7 @@ impl Backend for Void { /// Install the specified packages. fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new("sudo"); - cmd.arg(self.get_binary_install()); + cmd.arg(INSTALL_BINARY); cmd.args(self.get_switches_install()); if noconfirm { @@ -109,7 +91,7 @@ impl Backend for Void { fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new("sudo"); - cmd.arg(self.get_binary_remove()); + cmd.arg(REMOVE_BINARY); cmd.args(self.get_switches_remove()); if noconfirm { @@ -126,7 +108,7 @@ impl Backend for Void { fn make_dependency(&self, packages: &[Package]) -> Result { let mut cmd = Command::new("sudo"); - cmd.arg(self.get_binary_make_dependency()); + cmd.arg(PKGDB_BINARY); cmd.args(self.get_switches_make_dependency()); for p in packages { @@ -139,8 +121,8 @@ impl Backend for Void { } impl Void { - pub fn new() -> Self { - Void { + pub(crate) fn new() -> Self { + Self { packages: HashSet::new(), } } diff --git a/crates/pacdef_core/src/backend/mod.rs b/crates/pacdef_core/src/backend/mod.rs index 30215ac..623475f 100644 --- a/crates/pacdef_core/src/backend/mod.rs +++ b/crates/pacdef_core/src/backend/mod.rs @@ -16,10 +16,9 @@ pub enum Backends { Arch, #[cfg(feature = "debian")] Debian, - #[cfg(feature = "void")] - Void, Flatpak, Python, Rust, Rustup, + Void, } From fd1ba3ff2a904fece374cf4cd312f0096ad4ffa5 Mon Sep 17 00:00:00 2001 From: Samuel Talbot Date: Fri, 5 Apr 2024 08:01:09 +1300 Subject: [PATCH 5/7] fix package info --- crates/pacdef_core/src/backend/actual/void.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/void.rs b/crates/pacdef_core/src/backend/actual/void.rs index 7177de5..8917508 100644 --- a/crates/pacdef_core/src/backend/actual/void.rs +++ b/crates/pacdef_core/src/backend/actual/void.rs @@ -20,7 +20,7 @@ const QUERY_BINARY: Text = "xbps-query"; const PKGDB_BINARY: Text = "xbps-pkgdb"; const SECTION: Text = "void"; -const SWITCHES_INFO: Switches = &["-m"]; +const SWITCHES_INFO: Switches = &[]; const SWITCHES_INSTALL: Switches = &["-S"]; const SWITCHES_MAKE_DEPENDENCY: Switches = &["-m", "auto"]; const SWITCHES_NOCONFIRM: Switches = &["-y"]; @@ -58,7 +58,7 @@ impl Backend for Void { let re_str = r"-[^-]*$"; let re = Regex::new(re_str)?; let mut cmd = Command::new(QUERY_BINARY); - cmd.args(self.get_switches_info()); + cmd.args(["-m"]); let output = String::from_utf8(cmd.output()?.stdout)?; let packages: HashSet = output @@ -118,6 +118,15 @@ impl Backend for Void { cmd.status() .with_context(|| format!("running command [{cmd:?}]")) } + + /// Show information from package manager for package. + fn show_package_info(&self, package: &Package) -> Result { + let mut cmd = Command::new(QUERY_BINARY); + cmd.args(self.get_switches_info()); + cmd.arg(format!("{package}")); + cmd.status() + .with_context(|| format!("running command {cmd:?}")) + } } impl Void { From dbb14eb5b5a10f3f471315ce2ce90ba8ef7fe3ec Mon Sep 17 00:00:00 2001 From: Samuel Talbot Date: Fri, 5 Apr 2024 08:43:57 +1300 Subject: [PATCH 6/7] resolve issues --- crates/pacdef_core/Cargo.toml | 5 ++--- .../pacdef_core/src/backend/actual/debian.rs | 17 +--------------- crates/pacdef_core/src/backend/actual/void.rs | 20 +++++++++---------- crates/pacdef_core/src/backend/mod.rs | 1 + crates/pacdef_core/src/backend/root.rs | 17 ++++++++++++++++ 5 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 crates/pacdef_core/src/backend/root.rs diff --git a/crates/pacdef_core/Cargo.toml b/crates/pacdef_core/Cargo.toml index 802d8fa..95a5240 100644 --- a/crates/pacdef_core/Cargo.toml +++ b/crates/pacdef_core/Cargo.toml @@ -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"] diff --git a/crates/pacdef_core/src/backend/actual/debian.rs b/crates/pacdef_core/src/backend/actual/debian.rs index 55e2088..054a07d 100644 --- a/crates/pacdef_core/src/backend/actual/debian.rs +++ b/crates/pacdef_core/src/backend/actual/debian.rs @@ -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 -} diff --git a/crates/pacdef_core/src/backend/actual/void.rs b/crates/pacdef_core/src/backend/actual/void.rs index 8917508..de476cd 100644 --- a/crates/pacdef_core/src/backend/actual/void.rs +++ b/crates/pacdef_core/src/backend/actual/void.rs @@ -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 = 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 = 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 { - 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 { - 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 { - 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 { diff --git a/crates/pacdef_core/src/backend/mod.rs b/crates/pacdef_core/src/backend/mod.rs index 623475f..ab67304 100644 --- a/crates/pacdef_core/src/backend/mod.rs +++ b/crates/pacdef_core/src/backend/mod.rs @@ -2,6 +2,7 @@ mod actual; mod backend_trait; mod iter; mod macros; +mod root; mod todo_per_backend; pub use backend_trait::Backend; diff --git a/crates/pacdef_core/src/backend/root.rs b/crates/pacdef_core/src/backend/root.rs new file mode 100644 index 0000000..3f17861 --- /dev/null +++ b/crates/pacdef_core/src/backend/root.rs @@ -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 +} From 891830049b7252847507b253897146bbb3be3209 Mon Sep 17 00:00:00 2001 From: Samuel Talbot Date: Fri, 5 Apr 2024 08:52:21 +1300 Subject: [PATCH 7/7] remove unused import --- crates/pacdef_core/src/backend/actual/debian.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/pacdef_core/src/backend/actual/debian.rs b/crates/pacdef_core/src/backend/actual/debian.rs index 054a07d..075db4b 100644 --- a/crates/pacdef_core/src/backend/actual/debian.rs +++ b/crates/pacdef_core/src/backend/actual/debian.rs @@ -1,5 +1,4 @@ use std::collections::HashSet; -use std::process::Command; use std::process::ExitStatus; use anyhow::{Context, Result};