From 1b36fa84457ce721591b0e83c23612a74e9eec7f Mon Sep 17 00:00:00 2001 From: ripytide <62516857+ripytide@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:33:08 +0100 Subject: [PATCH] removed alpm dependency (#1) * removed alpm dependency * fix typo in arg Signed-off-by: innocentzero --------- Signed-off-by: innocentzero Co-authored-by: innocentzero --- Cargo.lock | 32 -------------------------------- Cargo.toml | 1 - src/backend/apt.rs | 1 - src/backend/arch.rs | 29 ++++++++++++++++------------- src/backend/dnf.rs | 1 - src/backend/flatpak.rs | 1 - src/backend/pip.rs | 9 +++------ 7 files changed, 19 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b950b7..73ff53d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,25 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "alpm" -version = "3.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "310ec5dc25b236ee96bebf975af2d2de85e61001a7c39a0a7436a414ff3f6490" -dependencies = [ - "alpm-sys", - "bitflags", -] - -[[package]] -name = "alpm-sys" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a17e0cf15a06d4b86e30c606ee8808ad791300f3bd5e364c30360354b010bd" -dependencies = [ - "pkg-config", -] - [[package]] name = "anstream" version = "0.6.13" @@ -84,12 +65,6 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - [[package]] name = "clap" version = "4.5.4" @@ -264,7 +239,6 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" name = "pacdef" version = "1.6.0" dependencies = [ - "alpm", "anyhow", "clap", "const_format", @@ -299,12 +273,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "proc-macro2" version = "1.0.79" diff --git a/Cargo.toml b/Cargo.toml index 34b3af5..a38e7e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ toml = "0.8" derive_more = "0.99" itertools = "0.12" -alpm = "3.0" # rust-apt = "0.7" [profile.release] diff --git a/src/backend/apt.rs b/src/backend/apt.rs index 878019e..e14c1f2 100644 --- a/src/backend/apt.rs +++ b/src/backend/apt.rs @@ -10,7 +10,6 @@ // #[derive(Debug, Copy, Clone, derive_more::Display)] // pub struct Apt; -// #[allow(dead_code)] // #[derive(Debug, Clone)] // pub struct AptQueryInfo { // explicit: bool, diff --git a/src/backend/arch.rs b/src/backend/arch.rs index e561234..a51acd3 100644 --- a/src/backend/arch.rs +++ b/src/backend/arch.rs @@ -1,17 +1,15 @@ -use alpm::{Alpm, PackageReason}; use anyhow::Result; use std::collections::BTreeMap; -use crate::cmd::run_args; +use crate::cmd::{command_found, run_args, run_args_for_stdout}; use crate::prelude::*; #[derive(Debug, Clone, Copy, derive_more::Display)] pub struct Arch; -#[allow(dead_code)] #[derive(Debug, Clone)] pub struct ArchQueryInfo { - reason: PackageReason, + pub explicit: bool, } pub struct ArchMakeImplicit; @@ -24,16 +22,21 @@ impl Backend for Arch { type Modification = ArchMakeImplicit; fn query_installed_packages(_: &Config) -> Result> { - let alpm = match Alpm::new("/", "/var/lib/pacman") { - Ok(x) => x, - Err(_) => return Ok(BTreeMap::new()), - }; + if !command_found("pacman") { + return Ok(BTreeMap::new()); + } - Ok(alpm - .localdb() - .pkgs() - .iter() - .map(|x| (x.name().to_string(), ArchQueryInfo { reason: x.reason() })) + let explicit = run_args_for_stdout(["pacman", "--query", "--explicit", "--quiet"])?; + let dependency = run_args_for_stdout(["pacman", "--query", "--deps", "--quiet"])?; + + Ok(dependency + .lines() + .map(|x| (x.to_string(), ArchQueryInfo { explicit: false })) + .chain( + explicit + .lines() + .map(|x| (x.to_string(), ArchQueryInfo { explicit: true })), + ) .collect()) } diff --git a/src/backend/dnf.rs b/src/backend/dnf.rs index a8c65e0..461402e 100644 --- a/src/backend/dnf.rs +++ b/src/backend/dnf.rs @@ -8,7 +8,6 @@ use crate::prelude::*; #[derive(Debug, Copy, Clone, derive_more::Display)] pub struct Dnf; -#[allow(dead_code)] #[derive(Debug, Clone)] pub struct DnfQueryInfo { user: bool, diff --git a/src/backend/flatpak.rs b/src/backend/flatpak.rs index aa1fc88..d5a9d64 100644 --- a/src/backend/flatpak.rs +++ b/src/backend/flatpak.rs @@ -8,7 +8,6 @@ use crate::prelude::*; #[derive(Debug, Copy, Clone, derive_more::Display)] pub struct Flatpak; -#[allow(dead_code)] #[derive(Debug, Clone)] pub struct FlatpakQueryInfo { explicit: bool, diff --git a/src/backend/pip.rs b/src/backend/pip.rs index 3228541..4e740c0 100644 --- a/src/backend/pip.rs +++ b/src/backend/pip.rs @@ -13,10 +13,9 @@ use crate::prelude::*; #[derive(Debug, Copy, Clone, derive_more::Display)] pub struct Pip; -#[allow(dead_code)] #[derive(Debug, Clone)] pub struct PipQueryInfo { - explicit: bool, + pub explicit: bool, } impl Backend for Pip { @@ -84,13 +83,11 @@ impl Backend for Pip { fn extract_package_names(stdout: String) -> Result> { let value: Value = serde_json::from_str(&stdout)?; - let result = value + Ok(value .as_array() .context("getting inner json array")? .iter() .map(|node| node["name"].as_str().expect("should always be a string")) .map(String::from) - .collect(); - - Ok(result) + .collect()) }