summaryrefslogtreecommitdiff
path: root/src/packages
diff options
context:
space:
mode:
authorfx <[email protected]>2024-09-23 18:56:39 +0200
committerfx <[email protected]>2024-09-23 18:56:39 +0200
commitec30fbab6ea45dcdec7d242fba2ff5555fea8e02 (patch)
tree131070807461d4808e17c34060d853e0985529ac /src/packages
parent0ed94b3f011a2d3c22bdc4affb502720be22c371 (diff)
downloadarbs-ec30fbab6ea45dcdec7d242fba2ff5555fea8e02.tar
arbs-ec30fbab6ea45dcdec7d242fba2ff5555fea8e02.tar.gz
arbs-ec30fbab6ea45dcdec7d242fba2ff5555fea8e02.zip
add dnf package manager
Diffstat (limited to 'src/packages')
-rw-r--r--src/packages/dnf.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/packages/dnf.rs b/src/packages/dnf.rs
new file mode 100644
index 0000000..aad9c8f
--- /dev/null
+++ b/src/packages/dnf.rs
@@ -0,0 +1,50 @@
1use std::process::Command;
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<()> { todo!() }
50}