From 26352160be07f719d83ec10dfda89815c9ba3b38 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 12:11:23 +0300 Subject: [PATCH 01/11] Add a minimal flatpak backend --- Cargo.toml | 1 + crates/pacdef_core/Cargo.toml | 1 + .../pacdef_core/src/backend/actual/flatpak.rs | 50 +++++++++++++++++++ crates/pacdef_core/src/backend/actual/mod.rs | 2 + crates/pacdef_core/src/backend/mod.rs | 2 + 5 files changed, 56 insertions(+) create mode 100644 crates/pacdef_core/src/backend/actual/flatpak.rs diff --git a/Cargo.toml b/Cargo.toml index 9c5abcc..4144687 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,4 @@ strip = true default = [] debian = ["pacdef_core/debian"] arch = ["pacdef_core/arch"] +flatpak = ["pacdef_core/flatpak"] diff --git a/crates/pacdef_core/Cargo.toml b/crates/pacdef_core/Cargo.toml index 6609230..7eeb0e5 100644 --- a/crates/pacdef_core/Cargo.toml +++ b/crates/pacdef_core/Cargo.toml @@ -35,3 +35,4 @@ rust-apt = { version = "0.5", optional = true } default = [] arch = ["dep:alpm"] debian = ["dep:rust-apt"] +flatpak = [] diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs new file mode 100644 index 0000000..705fff2 --- /dev/null +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -0,0 +1,50 @@ +use std::collections::HashSet; +use std::fs::read_to_string; +use std::path::PathBuf; +use std::process::ExitStatus; + +use anyhow::{Context, Result}; +use serde_json::Value; + +use crate::backend::backend_trait::{Backend, Switches, Text}; +use crate::{impl_backend_constants, Group, Package}; + +#[derive(Debug, Clone)] +pub struct Flatpak { + pub(crate) packages: HashSet, +} + +const BINARY: Text = "flatpak"; +const SECTION: Text = "flatpak"; + +const SWITCHES_INSTALL: Switches = &["install"]; +const SWITCHES_INFO: Switches = &[]; +const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; +const SWITCHES_NOCONFIRM: Switches = &[]; +const SWITCHES_REMOVE: Switches = &["uninstall"]; + +const SUPPORTS_AS_DEPENDENCY: bool = false; + +impl Backend for Flatpak { + impl_backend_constants!(); + + fn get_all_installed_packages(&self) -> Result> { + Ok(HashSet::new()) + } + + fn get_explicitly_installed_packages(&self) -> Result> { + Ok(HashSet::new()) + } + + fn make_dependency(&self, _: &[Package]) -> Result { + panic!("not supported by {}", BINARY) + } +} + +impl Flatpak { + pub(crate) fn new() -> Self { + Self { + packages: HashSet::new(), + } + } +} diff --git a/crates/pacdef_core/src/backend/actual/mod.rs b/crates/pacdef_core/src/backend/actual/mod.rs index c714208..c8f8ba6 100644 --- a/crates/pacdef_core/src/backend/actual/mod.rs +++ b/crates/pacdef_core/src/backend/actual/mod.rs @@ -4,3 +4,5 @@ pub mod arch; pub mod debian; pub mod python; pub mod rust; +#[cfg(feature = "flatpak")] +pub mod flatpak; diff --git a/crates/pacdef_core/src/backend/mod.rs b/crates/pacdef_core/src/backend/mod.rs index c8c10f1..19d6445 100644 --- a/crates/pacdef_core/src/backend/mod.rs +++ b/crates/pacdef_core/src/backend/mod.rs @@ -18,4 +18,6 @@ pub enum Backends { Debian, Python, Rust, + #[cfg(feature = "flatpak")] + Flatpak, } From 3f239795b7e9cfaa332425f446487e0ffc52a941 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 14:28:20 +0300 Subject: [PATCH 02/11] Add the ability to list installed flatpaks --- .../pacdef_core/src/backend/actual/flatpak.rs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 705fff2..02e7925 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -1,10 +1,8 @@ use std::collections::HashSet; -use std::fs::read_to_string; -use std::path::PathBuf; +use std::process::Command; use std::process::ExitStatus; use anyhow::{Context, Result}; -use serde_json::Value; use crate::backend::backend_trait::{Backend, Switches, Text}; use crate::{impl_backend_constants, Group, Package}; @@ -20,7 +18,7 @@ const SECTION: Text = "flatpak"; const SWITCHES_INSTALL: Switches = &["install"]; const SWITCHES_INFO: Switches = &[]; const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; -const SWITCHES_NOCONFIRM: Switches = &[]; +const SWITCHES_NOCONFIRM: Switches = &["--assumeyes"]; const SWITCHES_REMOVE: Switches = &["uninstall"]; const SUPPORTS_AS_DEPENDENCY: bool = false; @@ -29,11 +27,11 @@ impl Backend for Flatpak { impl_backend_constants!(); fn get_all_installed_packages(&self) -> Result> { - Ok(HashSet::new()) + Flatpak::get_installed_packages(true) } fn get_explicitly_installed_packages(&self) -> Result> { - Ok(HashSet::new()) + Flatpak::get_installed_packages(false) } fn make_dependency(&self, _: &[Package]) -> Result { @@ -47,4 +45,20 @@ impl Flatpak { packages: HashSet::new(), } } + + fn get_installed_packages(include_implicit: bool) -> Result> { + let mut cmd = Command::new(BINARY); + cmd.args(&["list", "--columns=application"]); + if !include_implicit { + cmd.arg("--app"); + } + + let output = String::from_utf8(cmd.output()?.stdout)?; + Ok( + output.lines() + .skip(1) + .map(|pkg| Package::from(pkg)) + .collect::>() + ) + } } From d03c338503a5b18b7c531f8e000a206b473fa1f6 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 16:58:18 +0300 Subject: [PATCH 03/11] Support flatpak info --- crates/pacdef_core/src/backend/actual/flatpak.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 02e7925..8235e1a 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::process::Command; use std::process::ExitStatus; -use anyhow::{Context, Result}; +use anyhow::Result; use crate::backend::backend_trait::{Backend, Switches, Text}; use crate::{impl_backend_constants, Group, Package}; @@ -16,7 +16,7 @@ const BINARY: Text = "flatpak"; const SECTION: Text = "flatpak"; const SWITCHES_INSTALL: Switches = &["install"]; -const SWITCHES_INFO: Switches = &[]; +const SWITCHES_INFO: Switches = &["info"]; const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; const SWITCHES_NOCONFIRM: Switches = &["--assumeyes"]; const SWITCHES_REMOVE: Switches = &["uninstall"]; From 6f10c789eb1925dae3eb2430dd26098c73a39726 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 18:32:29 +0300 Subject: [PATCH 04/11] Add flatpak_systemwide option --- crates/pacdef_core/src/backend/actual/flatpak.rs | 2 ++ crates/pacdef_core/src/config.rs | 3 +++ crates/pacdef_core/src/core.rs | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 8235e1a..100f595 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -10,6 +10,7 @@ use crate::{impl_backend_constants, Group, Package}; #[derive(Debug, Clone)] pub struct Flatpak { pub(crate) packages: HashSet, + pub(crate) systemwide: bool, } const BINARY: Text = "flatpak"; @@ -43,6 +44,7 @@ impl Flatpak { pub(crate) fn new() -> Self { Self { packages: HashSet::new(), + systemwide: true, } } diff --git a/crates/pacdef_core/src/config.rs b/crates/pacdef_core/src/config.rs index e0e39f8..d791425 100644 --- a/crates/pacdef_core/src/config.rs +++ b/crates/pacdef_core/src/config.rs @@ -13,6 +13,8 @@ pub struct Config { pub aur_helper: String, /// Additional arguments to pass to `aur_helper` when removing a package. pub aur_rm_args: Option>, + /// Install Flatpak packages system-wide + pub flatpak_systemwide: bool, /// Warn the user when a group is not a symlink. pub warn_not_symlinks: bool, /// Backends the user does not want to use even though the binary exists. @@ -68,6 +70,7 @@ impl Default for Config { Self { aur_helper: "paru".into(), aur_rm_args: None, + flatpak_systemwide: true, warn_not_symlinks: true, disabled_backends: vec![], } diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index 7a1cb67..dcda504 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -128,6 +128,13 @@ impl Pacdef { arch.aur_rm_args = self.config.aur_rm_args.take(); } } + + #[cfg(feature = "flatpak")] + { + if let Some(flatpak) = backend.as_any_mut().downcast_mut::() { + flatpak.systemwide = self.config.flatpak_systemwide; + } + } } fn install_packages(&mut self, args: &ArgMatches) -> Result<()> { From d559edc5773927de8034079db2a38a8470f950be Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 18:35:01 +0300 Subject: [PATCH 05/11] Fix flatpak-list skipping the first entry --- crates/pacdef_core/src/backend/actual/flatpak.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 8235e1a..af284db 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -56,7 +56,6 @@ impl Flatpak { let output = String::from_utf8(cmd.output()?.stdout)?; Ok( output.lines() - .skip(1) .map(|pkg| Package::from(pkg)) .collect::>() ) From a017a4ee755b8144748231fb9d43f9ab98b58b8e Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 19:07:39 +0300 Subject: [PATCH 06/11] Implement flatpak_systemwide option --- .../pacdef_core/src/backend/actual/flatpak.rs | 17 ++++++++++++++--- crates/pacdef_core/src/backend/backend_trait.rs | 9 +++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 100f595..e3dc6c3 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -27,12 +27,20 @@ const SUPPORTS_AS_DEPENDENCY: bool = false; impl Backend for Flatpak { impl_backend_constants!(); + fn get_switches_runtime(&self) -> Switches { + if self.systemwide { + &[] + } else { + &["--user"] + } + } + fn get_all_installed_packages(&self) -> Result> { - Flatpak::get_installed_packages(true) + self.get_installed_packages(true) } fn get_explicitly_installed_packages(&self) -> Result> { - Flatpak::get_installed_packages(false) + self.get_installed_packages(false) } fn make_dependency(&self, _: &[Package]) -> Result { @@ -48,12 +56,15 @@ impl Flatpak { } } - fn get_installed_packages(include_implicit: bool) -> Result> { + fn get_installed_packages(&self, include_implicit: bool) -> Result> { let mut cmd = Command::new(BINARY); cmd.args(&["list", "--columns=application"]); if !include_implicit { cmd.arg("--app"); } + if !self.systemwide { + cmd.arg("--user"); + } let output = String::from_utf8(cmd.output()?.stdout)?; Ok( diff --git a/crates/pacdef_core/src/backend/backend_trait.rs b/crates/pacdef_core/src/backend/backend_trait.rs index 8e6be52..9b84448 100644 --- a/crates/pacdef_core/src/backend/backend_trait.rs +++ b/crates/pacdef_core/src/backend/backend_trait.rs @@ -49,6 +49,11 @@ pub trait Backend: Debug { /// [`Backend::supports_as_dependency`]. fn get_switches_make_dependency(&self) -> Switches; + /// Get CLI switches evaluated at runtime + fn get_switches_runtime(&self) -> Switches { + &[] + } + /// Load all packages from a set of groups. The backend will visit all groups, /// find its own section, and clone all packages into its own struct. fn load(&mut self, groups: &HashSet); @@ -80,6 +85,7 @@ pub trait Backend: Debug { fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_install()); + cmd.args(self.get_switches_runtime()); if noconfirm { cmd.args(self.get_switches_noconfirm()); @@ -102,6 +108,7 @@ pub trait Backend: Debug { fn make_dependency(&self, packages: &[Package]) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_make_dependency()); + cmd.args(self.get_switches_runtime()); for p in packages { cmd.arg(format!("{p}")); @@ -115,6 +122,7 @@ pub trait Backend: Debug { fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_remove()); + cmd.args(self.get_switches_runtime()); if noconfirm { cmd.args(self.get_switches_noconfirm()); @@ -143,6 +151,7 @@ pub trait Backend: Debug { fn show_package_info(&self, package: &Package) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_info()); + cmd.args(self.get_switches_runtime()); cmd.arg(format!("{package}")); cmd.status() .with_context(|| format!("running command {cmd:?}")) From 0d509fdfa62d702f7b8c9435e7c7677d4a4ff332 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 19:22:56 +0300 Subject: [PATCH 07/11] Remove the unnecessary flatpak feature flag --- Cargo.toml | 1 - crates/pacdef_core/Cargo.toml | 1 - crates/pacdef_core/src/backend/actual/mod.rs | 1 - crates/pacdef_core/src/backend/mod.rs | 1 - crates/pacdef_core/src/core.rs | 7 ++----- 5 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4144687..9c5abcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,4 +33,3 @@ strip = true default = [] debian = ["pacdef_core/debian"] arch = ["pacdef_core/arch"] -flatpak = ["pacdef_core/flatpak"] diff --git a/crates/pacdef_core/Cargo.toml b/crates/pacdef_core/Cargo.toml index 7eeb0e5..6609230 100644 --- a/crates/pacdef_core/Cargo.toml +++ b/crates/pacdef_core/Cargo.toml @@ -35,4 +35,3 @@ rust-apt = { version = "0.5", optional = true } default = [] arch = ["dep:alpm"] debian = ["dep:rust-apt"] -flatpak = [] diff --git a/crates/pacdef_core/src/backend/actual/mod.rs b/crates/pacdef_core/src/backend/actual/mod.rs index c8f8ba6..8c61e68 100644 --- a/crates/pacdef_core/src/backend/actual/mod.rs +++ b/crates/pacdef_core/src/backend/actual/mod.rs @@ -4,5 +4,4 @@ pub mod arch; pub mod debian; pub mod python; pub mod rust; -#[cfg(feature = "flatpak")] pub mod flatpak; diff --git a/crates/pacdef_core/src/backend/mod.rs b/crates/pacdef_core/src/backend/mod.rs index 19d6445..444d883 100644 --- a/crates/pacdef_core/src/backend/mod.rs +++ b/crates/pacdef_core/src/backend/mod.rs @@ -18,6 +18,5 @@ pub enum Backends { Debian, Python, Rust, - #[cfg(feature = "flatpak")] Flatpak, } diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index dcda504..ce62d13 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -129,11 +129,8 @@ impl Pacdef { } } - #[cfg(feature = "flatpak")] - { - if let Some(flatpak) = backend.as_any_mut().downcast_mut::() { - flatpak.systemwide = self.config.flatpak_systemwide; - } + if let Some(flatpak) = backend.as_any_mut().downcast_mut::() { + flatpak.systemwide = self.config.flatpak_systemwide; } } From 8764221a27a23ab61bb27ed5b12f53ea9f8d5e55 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 19:30:13 +0300 Subject: [PATCH 08/11] Add flatpak backend to readme --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fd45f00..ff39a87 100644 --- a/README.md +++ b/README.md @@ -85,12 +85,13 @@ Note that the name of the section corresponds to the ecosystem it relates to, ra At the moment, supported backends are the following. Pull requests for additional backends are welcome! -| Application | Package Manager | Section | feature flag | Notes | -|-------------|-----------------|-----------|--------------|-----------------------------------------------------------------------------------------------------------| -| Arch Linux | `pacman` | `[arch]` | `arch` | includes pacman-wrapping AUR helpers (configurable) | -| Debian | `apt` | `[debian]`| `debian` | minimum supported apt-version unknown ([upstream issue](https://gitlab.com/volian/rust-apt/-/issues/20)) | -| Python | `pip` | `[python]`| built-in | | -| Rust | `cargo` | `[rust]` | built-in | | +| Application | Package Manager | Section | feature flag | Notes | +|-------------|-----------------|-------------|--------------|-----------------------------------------------------------------------------------------------------------| +| Arch Linux | `pacman` | `[arch]` | `arch` | includes pacman-wrapping AUR helpers (configurable) | +| Debian | `apt` | `[debian]` | `debian` | minimum supported apt-version unknown ([upstream issue](https://gitlab.com/volian/rust-apt/-/issues/20)) | +| Python | `pip` | `[python]` | built-in | | +| Rust | `cargo` | `[rust]` | built-in | | +| Flatpak | `flatpak` | `[flatpak]` | built-in | can manage either system-wide or per-user installation (configurable) | 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`. From 39496e836eee161eacf2e4c8a7a5b020137c0d6c Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 19:42:53 +0300 Subject: [PATCH 09/11] Fix formatting --- crates/pacdef_core/src/backend/actual/flatpak.rs | 11 +++++------ crates/pacdef_core/src/backend/actual/mod.rs | 2 +- crates/pacdef_core/src/backend/backend_trait.rs | 2 +- crates/pacdef_core/src/core.rs | 5 ++++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 43a275c..8d23d64 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -58,7 +58,7 @@ impl Flatpak { fn get_installed_packages(&self, include_implicit: bool) -> Result> { let mut cmd = Command::new(BINARY); - cmd.args(&["list", "--columns=application"]); + cmd.args(["list", "--columns=application"]); if !include_implicit { cmd.arg("--app"); } @@ -67,10 +67,9 @@ impl Flatpak { } let output = String::from_utf8(cmd.output()?.stdout)?; - Ok( - output.lines() - .map(|pkg| Package::from(pkg)) - .collect::>() - ) + Ok(output + .lines() + .map(Package::from) + .collect::>()) } } diff --git a/crates/pacdef_core/src/backend/actual/mod.rs b/crates/pacdef_core/src/backend/actual/mod.rs index 8c61e68..a30c8c1 100644 --- a/crates/pacdef_core/src/backend/actual/mod.rs +++ b/crates/pacdef_core/src/backend/actual/mod.rs @@ -2,6 +2,6 @@ pub mod arch; #[cfg(feature = "debian")] pub mod debian; +pub mod flatpak; pub mod python; pub mod rust; -pub mod flatpak; diff --git a/crates/pacdef_core/src/backend/backend_trait.rs b/crates/pacdef_core/src/backend/backend_trait.rs index 9b84448..4b7c481 100644 --- a/crates/pacdef_core/src/backend/backend_trait.rs +++ b/crates/pacdef_core/src/backend/backend_trait.rs @@ -186,7 +186,7 @@ where let mut map = HashMap::new(); for (value, key) in to_assign { - let inner = map.entry(key).or_insert(vec![]); + let inner: &mut Vec = map.entry(key).or_default(); inner.push(value); } diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index ce62d13..63110d3 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -129,7 +129,10 @@ impl Pacdef { } } - if let Some(flatpak) = backend.as_any_mut().downcast_mut::() { + if let Some(flatpak) = backend + .as_any_mut() + .downcast_mut::() + { flatpak.systemwide = self.config.flatpak_systemwide; } } From a38a1865f51753c702129e6bf6ab4bafd6a87490 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 19:48:54 +0300 Subject: [PATCH 10/11] Alphabetical order --- README.md | 2 +- crates/pacdef_core/src/backend/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff39a87..fcf088d 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,9 @@ 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 unknown ([upstream issue](https://gitlab.com/volian/rust-apt/-/issues/20)) | +| 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 | | -| Flatpak | `flatpak` | `[flatpak]` | built-in | can manage either system-wide or per-user installation (configurable) | 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/src/backend/mod.rs b/crates/pacdef_core/src/backend/mod.rs index 444d883..7e39d3d 100644 --- a/crates/pacdef_core/src/backend/mod.rs +++ b/crates/pacdef_core/src/backend/mod.rs @@ -16,7 +16,7 @@ pub enum Backends { Arch, #[cfg(feature = "debian")] Debian, + Flatpak, Python, Rust, - Flatpak, } From 54acb132b5c89c5d52ca002eaa2338fda8b3de64 Mon Sep 17 00:00:00 2001 From: teackot Date: Tue, 16 May 2023 20:15:10 +0300 Subject: [PATCH 11/11] Revert the switches_runtime change; implement flatpak-specific functions. --- .../pacdef_core/src/backend/actual/flatpak.rs | 64 ++++++++++++++++--- .../pacdef_core/src/backend/backend_trait.rs | 9 --- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 8d23d64..47bcf9e 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::process::Command; use std::process::ExitStatus; -use anyhow::Result; +use anyhow::{Context, Result}; use crate::backend::backend_trait::{Backend, Switches, Text}; use crate::{impl_backend_constants, Group, Package}; @@ -27,14 +27,6 @@ const SUPPORTS_AS_DEPENDENCY: bool = false; impl Backend for Flatpak { impl_backend_constants!(); - fn get_switches_runtime(&self) -> Switches { - if self.systemwide { - &[] - } else { - &["--user"] - } - } - fn get_all_installed_packages(&self) -> Result> { self.get_installed_packages(true) } @@ -43,9 +35,55 @@ impl Backend for Flatpak { self.get_installed_packages(false) } + /// Install the specified packages. + fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { + let mut cmd = Command::new(self.get_binary()); + cmd.args(self.get_switches_install()); + cmd.args(self.get_switches_runtime()); + + 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, _: &[Package]) -> Result { panic!("not supported by {}", BINARY) } + + /// Remove the specified packages. + fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { + let mut cmd = Command::new(self.get_binary()); + cmd.args(self.get_switches_remove()); + cmd.args(self.get_switches_runtime()); + + if noconfirm { + cmd.args(self.get_switches_noconfirm()); + } + + for p in packages { + cmd.arg(format!("{p}")); + } + + 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(self.get_binary()); + cmd.args(self.get_switches_info()); + cmd.args(self.get_switches_runtime()); + cmd.arg(format!("{package}")); + cmd.status() + .with_context(|| format!("running command {cmd:?}")) + } } impl Flatpak { @@ -56,6 +94,14 @@ impl Flatpak { } } + fn get_switches_runtime(&self) -> Switches { + if self.systemwide { + &[] + } else { + &["--user"] + } + } + fn get_installed_packages(&self, include_implicit: bool) -> Result> { let mut cmd = Command::new(BINARY); cmd.args(["list", "--columns=application"]); diff --git a/crates/pacdef_core/src/backend/backend_trait.rs b/crates/pacdef_core/src/backend/backend_trait.rs index 4b7c481..98cfddb 100644 --- a/crates/pacdef_core/src/backend/backend_trait.rs +++ b/crates/pacdef_core/src/backend/backend_trait.rs @@ -49,11 +49,6 @@ pub trait Backend: Debug { /// [`Backend::supports_as_dependency`]. fn get_switches_make_dependency(&self) -> Switches; - /// Get CLI switches evaluated at runtime - fn get_switches_runtime(&self) -> Switches { - &[] - } - /// Load all packages from a set of groups. The backend will visit all groups, /// find its own section, and clone all packages into its own struct. fn load(&mut self, groups: &HashSet); @@ -85,7 +80,6 @@ pub trait Backend: Debug { fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_install()); - cmd.args(self.get_switches_runtime()); if noconfirm { cmd.args(self.get_switches_noconfirm()); @@ -108,7 +102,6 @@ pub trait Backend: Debug { fn make_dependency(&self, packages: &[Package]) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_make_dependency()); - cmd.args(self.get_switches_runtime()); for p in packages { cmd.arg(format!("{p}")); @@ -122,7 +115,6 @@ pub trait Backend: Debug { fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_remove()); - cmd.args(self.get_switches_runtime()); if noconfirm { cmd.args(self.get_switches_noconfirm()); @@ -151,7 +143,6 @@ pub trait Backend: Debug { fn show_package_info(&self, package: &Package) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_info()); - cmd.args(self.get_switches_runtime()); cmd.arg(format!("{package}")); cmd.status() .with_context(|| format!("running command {cmd:?}"))