Merge branch 'flatpak-per-user' into flatpak-backend
This commit is contained in:
@@ -10,6 +10,7 @@ use crate::{impl_backend_constants, Group, Package};
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Flatpak {
|
pub struct Flatpak {
|
||||||
pub(crate) packages: HashSet<Package>,
|
pub(crate) packages: HashSet<Package>,
|
||||||
|
pub(crate) systemwide: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const BINARY: Text = "flatpak";
|
const BINARY: Text = "flatpak";
|
||||||
@@ -26,12 +27,20 @@ const SUPPORTS_AS_DEPENDENCY: bool = false;
|
|||||||
impl Backend for Flatpak {
|
impl Backend for Flatpak {
|
||||||
impl_backend_constants!();
|
impl_backend_constants!();
|
||||||
|
|
||||||
|
fn get_switches_runtime(&self) -> Switches {
|
||||||
|
if self.systemwide {
|
||||||
|
&[]
|
||||||
|
} else {
|
||||||
|
&["--user"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||||
Flatpak::get_installed_packages(true)
|
self.get_installed_packages(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
|
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||||
Flatpak::get_installed_packages(false)
|
self.get_installed_packages(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_dependency(&self, _: &[Package]) -> Result<ExitStatus> {
|
fn make_dependency(&self, _: &[Package]) -> Result<ExitStatus> {
|
||||||
@@ -43,15 +52,19 @@ impl Flatpak {
|
|||||||
pub(crate) fn new() -> Self {
|
pub(crate) fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
packages: HashSet::new(),
|
packages: HashSet::new(),
|
||||||
|
systemwide: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_installed_packages(include_implicit: bool) -> Result<HashSet<Package>> {
|
fn get_installed_packages(&self, include_implicit: bool) -> Result<HashSet<Package>> {
|
||||||
let mut cmd = Command::new(BINARY);
|
let mut cmd = Command::new(BINARY);
|
||||||
cmd.args(&["list", "--columns=application"]);
|
cmd.args(&["list", "--columns=application"]);
|
||||||
if !include_implicit {
|
if !include_implicit {
|
||||||
cmd.arg("--app");
|
cmd.arg("--app");
|
||||||
}
|
}
|
||||||
|
if !self.systemwide {
|
||||||
|
cmd.arg("--user");
|
||||||
|
}
|
||||||
|
|
||||||
let output = String::from_utf8(cmd.output()?.stdout)?;
|
let output = String::from_utf8(cmd.output()?.stdout)?;
|
||||||
Ok(
|
Ok(
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ pub trait Backend: Debug {
|
|||||||
/// [`Backend::supports_as_dependency`].
|
/// [`Backend::supports_as_dependency`].
|
||||||
fn get_switches_make_dependency(&self) -> Switches;
|
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,
|
/// 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.
|
/// find its own section, and clone all packages into its own struct.
|
||||||
fn load(&mut self, groups: &HashSet<Group>);
|
fn load(&mut self, groups: &HashSet<Group>);
|
||||||
@@ -80,6 +85,7 @@ pub trait Backend: Debug {
|
|||||||
fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result<ExitStatus> {
|
fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result<ExitStatus> {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(self.get_switches_install());
|
cmd.args(self.get_switches_install());
|
||||||
|
cmd.args(self.get_switches_runtime());
|
||||||
|
|
||||||
if noconfirm {
|
if noconfirm {
|
||||||
cmd.args(self.get_switches_noconfirm());
|
cmd.args(self.get_switches_noconfirm());
|
||||||
@@ -102,6 +108,7 @@ pub trait Backend: Debug {
|
|||||||
fn make_dependency(&self, packages: &[Package]) -> Result<ExitStatus> {
|
fn make_dependency(&self, packages: &[Package]) -> Result<ExitStatus> {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(self.get_switches_make_dependency());
|
cmd.args(self.get_switches_make_dependency());
|
||||||
|
cmd.args(self.get_switches_runtime());
|
||||||
|
|
||||||
for p in packages {
|
for p in packages {
|
||||||
cmd.arg(format!("{p}"));
|
cmd.arg(format!("{p}"));
|
||||||
@@ -115,6 +122,7 @@ pub trait Backend: Debug {
|
|||||||
fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result<ExitStatus> {
|
fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result<ExitStatus> {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(self.get_switches_remove());
|
cmd.args(self.get_switches_remove());
|
||||||
|
cmd.args(self.get_switches_runtime());
|
||||||
|
|
||||||
if noconfirm {
|
if noconfirm {
|
||||||
cmd.args(self.get_switches_noconfirm());
|
cmd.args(self.get_switches_noconfirm());
|
||||||
@@ -143,6 +151,7 @@ pub trait Backend: Debug {
|
|||||||
fn show_package_info(&self, package: &Package) -> Result<ExitStatus> {
|
fn show_package_info(&self, package: &Package) -> Result<ExitStatus> {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(self.get_switches_info());
|
cmd.args(self.get_switches_info());
|
||||||
|
cmd.args(self.get_switches_runtime());
|
||||||
cmd.arg(format!("{package}"));
|
cmd.arg(format!("{package}"));
|
||||||
cmd.status()
|
cmd.status()
|
||||||
.with_context(|| format!("running command {cmd:?}"))
|
.with_context(|| format!("running command {cmd:?}"))
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ pub struct Config {
|
|||||||
pub aur_helper: String,
|
pub aur_helper: String,
|
||||||
/// Additional arguments to pass to `aur_helper` when removing a package.
|
/// Additional arguments to pass to `aur_helper` when removing a package.
|
||||||
pub aur_rm_args: Option<Vec<String>>,
|
pub aur_rm_args: Option<Vec<String>>,
|
||||||
|
/// Install Flatpak packages system-wide
|
||||||
|
pub flatpak_systemwide: bool,
|
||||||
/// Warn the user when a group is not a symlink.
|
/// Warn the user when a group is not a symlink.
|
||||||
pub warn_not_symlinks: bool,
|
pub warn_not_symlinks: bool,
|
||||||
/// Backends the user does not want to use even though the binary exists.
|
/// Backends the user does not want to use even though the binary exists.
|
||||||
@@ -68,6 +70,7 @@ impl Default for Config {
|
|||||||
Self {
|
Self {
|
||||||
aur_helper: "paru".into(),
|
aur_helper: "paru".into(),
|
||||||
aur_rm_args: None,
|
aur_rm_args: None,
|
||||||
|
flatpak_systemwide: true,
|
||||||
warn_not_symlinks: true,
|
warn_not_symlinks: true,
|
||||||
disabled_backends: vec![],
|
disabled_backends: vec![],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,6 +128,13 @@ impl Pacdef {
|
|||||||
arch.aur_rm_args = self.config.aur_rm_args.take();
|
arch.aur_rm_args = self.config.aur_rm_args.take();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "flatpak")]
|
||||||
|
{
|
||||||
|
if let Some(flatpak) = backend.as_any_mut().downcast_mut::<crate::backend::Flatpak>() {
|
||||||
|
flatpak.systemwide = self.config.flatpak_systemwide;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_packages(&mut self, args: &ArgMatches) -> Result<()> {
|
fn install_packages(&mut self, args: &ArgMatches) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user