Skip to content

Commit

Permalink
check flatpak-pin with installed packages
Browse files Browse the repository at this point in the history
Signed-off-by: innocentzero <[email protected]>
  • Loading branch information
InnocentZero committed Nov 2, 2024
1 parent 4457cdf commit 7231a8e
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions src/backends/flatpak.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7231a8e

Please sign in to comment.