summaryrefslogtreecommitdiff
path: root/src/packages
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-29 15:31:54 +0200
committerfxqnlr <[email protected]>2024-09-29 15:31:54 +0200
commit83ac2ad62c27a3089f892b409405f74c4952f2da (patch)
tree176b819060c5da7ae83510bedec784401a7533d1 /src/packages
parent5f23d5506698081722eef6e34f11c7fb24e0b212 (diff)
parentd1a9d0d8a8746a63b93f8f14ee4f51b1cd240349 (diff)
downloadarbs-83ac2ad62c27a3089f892b409405f74c4952f2da.tar
arbs-83ac2ad62c27a3089f892b409405f74c4952f2da.tar.gz
arbs-83ac2ad62c27a3089f892b409405f74c4952f2da.zip
Merge remote-tracking branch 'origin/dnf'
Diffstat (limited to 'src/packages')
-rw-r--r--src/packages/dnf.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/packages/dnf.rs b/src/packages/dnf.rs
new file mode 100644
index 0000000..6f451ee
--- /dev/null
+++ b/src/packages/dnf.rs
@@ -0,0 +1,62 @@
1use std::process::{Command, Stdio};
2
3use super::{Package, PackageList, PackageManager};
4
5use crate::error::{Error, Result};
6
7pub struct Dnf;
8
9impl PackageManager for Dnf {
10 fn get_installed(&self) -> Result<PackageList> {
11 let list = Command::new("dnf").args(["list", "installed"]).output().unwrap();
12 let explicit_list = Command::new("dnf").args(["repoquery", "--userinstalled"]).output().unwrap();
13
14 let list_str = String::from_utf8(list.stdout).unwrap();
15 let ex_list_str = String::from_utf8(explicit_list.stdout).unwrap();
16
17
18 let mut pkgs: Vec<Package> = Vec::new();
19 let list_lines: Vec<&str> = list_str.split('\n').collect();
20 // Pop first info line
21 let list_lines = &list_lines[1..list_lines.len()];
22 for pkg in list_lines {
23 if pkg.is_empty() {
24 continue;
25 };
26 let split: Vec<&str> = pkg.split_whitespace().collect();
27 if split.len() != 3 {
28 return Err(Error::UnknownOutput);
29 };
30
31 let explicit = ex_list_str.contains(pkg);
32
33 let Some(pkg_id) = split[0].split_once('.') else {
34 return Err(Error::UnknownOutput);
35 };
36 pkgs.push(Package {
37 id: pkg_id.0.to_string(),
38 version: split[1].to_string(),
39 explicit,
40 });
41 }
42
43 Ok(PackageList {
44 packages: pkgs,
45 manager: super::Manager::Dnf,
46 })
47 }
48
49 fn install(&self, pkgs: Vec<super::Package>) -> Result<()> {
50 let mut args = vec!["dnf".to_string(), "install".to_string(), "--assumeyes".to_string()];
51
52 for pkg in pkgs {
53 args.push(pkg.id);
54 }
55 Command::new("sudo")
56 .stdout(Stdio::inherit())
57 .args(args)
58 .spawn()?
59 .wait_with_output()?;
60 Ok(())
61 }
62}