From 3e1cb020d5449849b37874f91cadfa4a9c878747 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 6 Sep 2024 10:56:30 +0200 Subject: initial commit, can save index, no modification check --- src/packages/pacman.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/packages/pacman.rs (limited to 'src/packages') diff --git a/src/packages/pacman.rs b/src/packages/pacman.rs new file mode 100644 index 0000000..0a9e1ff --- /dev/null +++ b/src/packages/pacman.rs @@ -0,0 +1,46 @@ +use std::process::Command; + +use crate::packages::Package; + +use super::PackageManager; + +pub struct Pacman; + +impl PackageManager for Pacman { + fn get_installed(&self) -> Vec { + let pm_pkgs = Command::new("pacman").args(["-Q"]).output().unwrap(); + let pm_e_pkgs = Command::new("pacman") + .args(["-Q", "--explicit"]) + .output() + .unwrap(); + + let pm_pkgs_out = String::from_utf8(pm_pkgs.stdout).unwrap(); + let pm_e_pkgs_out = String::from_utf8(pm_e_pkgs.stdout).unwrap(); + + let mut pkgs: Vec = Vec::new(); + let pacman_pkgs: Vec<&str> = pm_pkgs_out.split('\n').collect(); + for pkg in pacman_pkgs { + if pkg.is_empty() { + continue; + }; + let split: Vec<&str> = pkg.split_whitespace().collect(); + if split.len() != 2 { + panic!("Unknown Pacman Output"); + }; + + let explicit = pm_e_pkgs_out.contains(pkg); + + pkgs.push(Package { + id: split[0].to_string(), + version: split[1].to_string(), + explicit + }) + } + + pkgs + } + + fn install(&self, pkgs: Vec) { + todo!(); + } +} -- cgit v1.2.3