summaryrefslogtreecommitdiff
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
parent0ed94b3f011a2d3c22bdc4affb502720be22c371 (diff)
downloadarbs-ec30fbab6ea45dcdec7d242fba2ff5555fea8e02.tar
arbs-ec30fbab6ea45dcdec7d242fba2ff5555fea8e02.tar.gz
arbs-ec30fbab6ea45dcdec7d242fba2ff5555fea8e02.zip
add dnf package manager
-rw-r--r--src/packages.rs5
-rw-r--r--src/packages/dnf.rs50
2 files changed, 55 insertions, 0 deletions
diff --git a/src/packages.rs b/src/packages.rs
index de818f4..2844a9b 100644
--- a/src/packages.rs
+++ b/src/packages.rs
@@ -1,11 +1,13 @@
1use std::{fs::File, io::Read}; 1use std::{fs::File, io::Read};
2 2
3use dnf::Dnf;
3use pacman::Pacman; 4use pacman::Pacman;
4use portage::Portage; 5use portage::Portage;
5use serde::{Deserialize, Serialize}; 6use serde::{Deserialize, Serialize};
6 7
7use crate::error::{Error, Result}; 8use crate::error::{Error, Result};
8 9
10mod dnf;
9mod pacman; 11mod pacman;
10mod portage; 12mod portage;
11 13
@@ -32,6 +34,7 @@ pub struct Package {
32 34
33#[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)] 35#[derive(Debug, Clone, clap::ValueEnum, Serialize, Deserialize)]
34pub enum Manager { 36pub enum Manager {
37 Dnf,
35 Pacman, 38 Pacman,
36 Portage, 39 Portage,
37} 40}
@@ -65,6 +68,7 @@ impl Manager {
65 68
66 fn from_str(value: &str) -> Result<Box<dyn PackageManager>> { 69 fn from_str(value: &str) -> Result<Box<dyn PackageManager>> {
67 Ok(match value { 70 Ok(match value {
71 "fedora" => Box::new(Dnf),
68 "arch" => Box::new(Pacman), 72 "arch" => Box::new(Pacman),
69 "gentoo" => Box::new(Portage), 73 "gentoo" => Box::new(Portage),
70 _ => return Err(Error::Unsupported), 74 _ => return Err(Error::Unsupported),
@@ -73,6 +77,7 @@ impl Manager {
73 77
74 fn to_package_manager(&self) -> Box<dyn PackageManager> { 78 fn to_package_manager(&self) -> Box<dyn PackageManager> {
75 match self { 79 match self {
80 Self::Dnf => Box::new(Dnf),
76 Self::Pacman => Box::new(Pacman), 81 Self::Pacman => Box::new(Pacman),
77 Self::Portage => Box::new(Portage), 82 Self::Portage => Box::new(Portage),
78 } 83 }
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}