From e1e1ef00832b370e5e482d5f8db1bec62ee6173e Mon Sep 17 00:00:00 2001 From: innocentzero Date: Sat, 2 Nov 2024 14:56:56 +0530 Subject: [PATCH 1/4] Add author Signed-off-by: innocentzero --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4fd6047..6e2c0aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/ripytide/metapac" readme = "README.md" keywords = ["package-manager", "linux", "declarative", "cli"] categories = ["command-line-utilities"] -authors = ["James Forster "] +authors = ["James Forster ", "Md Isfarul Haque Date: Sat, 2 Nov 2024 14:57:20 +0530 Subject: [PATCH 2/4] Manage pinned flatpak runtimes This patch series attempts to add support to manage the pinned runtimes of flatpak. Signed-off-by: innocentzero --- src/backends/flatpak.rs | 53 ++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/backends/flatpak.rs b/src/backends/flatpak.rs index cbb1142..234856d 100644 --- a/src/backends/flatpak.rs +++ b/src/backends/flatpak.rs @@ -33,7 +33,7 @@ impl Backend for Flatpak { return Ok(BTreeMap::new()); } - let sys_explicit_btree = run_command_for_stdout( + let sys_explicit_out = run_command_for_stdout( [ "flatpak", "list", @@ -42,12 +42,12 @@ impl Backend for Flatpak { "--columns=application", ], Perms::Same, - )? - .lines() - .map(String::from) - .collect::>(); + )?; + let sys_explicit = sys_explicit_out + .lines() + .map(|x| (x.trim().to_owned(), FlatpakQueryInfo { systemwide: true })); - let user_explicit_btree = run_command_for_stdout( + let user_explicit_out = run_command_for_stdout( [ "flatpak", "list", @@ -56,19 +56,34 @@ impl Backend for Flatpak { "--columns=application", ], Perms::Same, - )? - .lines() - .map(String::from) - .collect::>(); - - let sys_explicit = sys_explicit_btree - .iter() - .map(|x| (x.clone(), FlatpakQueryInfo { systemwide: true })); - let user_explicit = user_explicit_btree - .iter() - .map(|x| (x.clone(), FlatpakQueryInfo { systemwide: false })); - - let all = sys_explicit.chain(user_explicit).collect(); + )?; + let user_explicit = user_explicit_out + .lines() + .map(|x| (x.trim().to_owned(), FlatpakQueryInfo { systemwide: false })); + + let sys_explicit_runtimes_out = + run_command_for_stdout(["flatpak", "pin", "--system"], Perms::Same)?; + let sys_explicit_runtimes = sys_explicit_runtimes_out.lines().skip(1).map(|x| { + ( + x.trim().split('/').nth(1).unwrap().to_owned(), + FlatpakQueryInfo { systemwide: true }, + ) + }); + + let user_explicit_runtimes_out = + run_command_for_stdout(["flatpak", "pin", "--user"], Perms::Same)?; + let user_explicit_runtimes = user_explicit_runtimes_out.lines().skip(1).map(|x| { + ( + x.trim().split('/').nth(1).unwrap().to_owned(), + FlatpakQueryInfo { systemwide: false }, + ) + }); + + let all = sys_explicit + .chain(user_explicit) + .chain(sys_explicit_runtimes) + .chain(user_explicit_runtimes) + .collect(); Ok(all) } From 7231a8e49a33c72cf4d52c3a579a412dfc3ce781 Mon Sep 17 00:00:00 2001 From: innocentzero Date: Sat, 2 Nov 2024 15:53:54 +0530 Subject: [PATCH 3/4] check flatpak-pin with installed packages Signed-off-by: innocentzero --- src/backends/flatpak.rs | 67 +++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/src/backends/flatpak.rs b/src/backends/flatpak.rs index 234856d..4a7d60f 100644 --- a/src/backends/flatpak.rs +++ b/src/backends/flatpak.rs @@ -1,6 +1,7 @@ use std::collections::{BTreeMap, BTreeSet}; use color_eyre::Result; +use itertools::Itertools; use serde::{Deserialize, Serialize}; use crate::cmd::{command_found, run_command, run_command_for_stdout}; @@ -61,23 +62,63 @@ impl Backend for Flatpak { .lines() .map(|x| (x.trim().to_owned(), FlatpakQueryInfo { systemwide: false })); + let sys_explicit_runtimes_installed = run_command_for_stdout( + [ + "flatpak", + "list", + "--system", + "--runtime", + "--columns=application", + ], + Perms::Same, + )?; let sys_explicit_runtimes_out = run_command_for_stdout(["flatpak", "pin", "--system"], Perms::Same)?; - let sys_explicit_runtimes = sys_explicit_runtimes_out.lines().skip(1).map(|x| { - ( - x.trim().split('/').nth(1).unwrap().to_owned(), - FlatpakQueryInfo { systemwide: true }, - ) - }); - + let sys_explicit_runtimes = sys_explicit_runtimes_out + .lines() + .skip(1) + .map(|x| { + ( + x.trim().split('/').nth(1).unwrap().to_owned(), + FlatpakQueryInfo { systemwide: true }, + ) + }) + .filter(|(runtime, _)| { + sys_explicit_runtimes_installed + .lines() + .skip(1) + .map(|x| x.trim()) + .contains(&runtime.as_str()) + }); + + let user_explicit_runtimes_installed = run_command_for_stdout( + [ + "flatpak", + "list", + "--user", + "--runtime", + "--columns=application", + ], + Perms::Same, + )?; let user_explicit_runtimes_out = run_command_for_stdout(["flatpak", "pin", "--user"], Perms::Same)?; - let user_explicit_runtimes = user_explicit_runtimes_out.lines().skip(1).map(|x| { - ( - x.trim().split('/').nth(1).unwrap().to_owned(), - FlatpakQueryInfo { systemwide: false }, - ) - }); + let user_explicit_runtimes = user_explicit_runtimes_out + .lines() + .skip(1) + .map(|x| { + ( + x.trim().split('/').nth(1).unwrap().to_owned(), + FlatpakQueryInfo { systemwide: false }, + ) + }) + .filter(|(runtime, _)| { + user_explicit_runtimes_installed + .lines() + .skip(1) + .map(|x| x.trim()) + .contains(&runtime.as_str()) + }); let all = sys_explicit .chain(user_explicit) From 93864c4b33d9999bf796db53322c783421041837 Mon Sep 17 00:00:00 2001 From: innocentzero Date: Sat, 2 Nov 2024 15:54:07 +0530 Subject: [PATCH 4/4] dont use sudo with flatpaks Signed-off-by: innocentzero --- src/backends/flatpak.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/flatpak.rs b/src/backends/flatpak.rs index 4a7d60f..d265396 100644 --- a/src/backends/flatpak.rs +++ b/src/backends/flatpak.rs @@ -148,7 +148,7 @@ impl Backend for Flatpak { .into_iter() .chain(Some("--assumeyes").filter(|_| no_confirm)) .chain(packages.keys().map(String::as_str)), - Perms::Sudo, + Perms::Same, )?; }