Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pinned flatpak runtimes #40

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
authors = ["James Forster <[email protected]>", "Md Isfarul Haque <[email protected]"]
include = [
"build.rs",
"src/**/*",
Expand Down
94 changes: 75 additions & 19 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 @@ -33,7 +34,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",
Expand All @@ -42,12 +43,12 @@ impl Backend for Flatpak {
"--columns=application",
],
Perms::Same,
)?
.lines()
.map(String::from)
.collect::<BTreeSet<_>>();
)?;
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",
Expand All @@ -56,19 +57,74 @@ impl Backend for Flatpak {
"--columns=application",
],
Perms::Same,
)?
.lines()
.map(String::from)
.collect::<BTreeSet<_>>();
)?;
let user_explicit = user_explicit_out
.lines()
.map(|x| (x.trim().to_owned(), FlatpakQueryInfo { systemwide: false }));

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 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 },
)
})
.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 },
)
})
.filter(|(runtime, _)| {
user_explicit_runtimes_installed
.lines()
.skip(1)
.map(|x| x.trim())
.contains(&runtime.as_str())
});

let all = sys_explicit
.chain(user_explicit)
.chain(sys_explicit_runtimes)
.chain(user_explicit_runtimes)
.collect();

Ok(all)
}
Expand All @@ -92,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,
)?;
}

Expand Down