Skip to content

Commit

Permalink
removed alpm dependency (#1)
Browse files Browse the repository at this point in the history
* removed alpm dependency

* fix typo in arg

Signed-off-by: innocentzero <[email protected]>

---------

Signed-off-by: innocentzero <[email protected]>
Co-authored-by: innocentzero <[email protected]>
  • Loading branch information
ripytide and InnocentZero authored Aug 28, 2024
1 parent 682e4e4 commit 1b36fa8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 55 deletions.
32 changes: 0 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ toml = "0.8"
derive_more = "0.99"
itertools = "0.12"

alpm = "3.0"
# rust-apt = "0.7"

[profile.release]
Expand Down
1 change: 0 additions & 1 deletion src/backend/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 16 additions & 13 deletions src/backend/arch.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,16 +22,21 @@ impl Backend for Arch {
type Modification = ArchMakeImplicit;

fn query_installed_packages(_: &Config) -> Result<BTreeMap<Self::PackageId, Self::QueryInfo>> {
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())
}

Expand Down
1 change: 0 additions & 1 deletion src/backend/dnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/backend/flatpak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions src/backend/pip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -84,13 +83,11 @@ impl Backend for Pip {
fn extract_package_names(stdout: String) -> Result<BTreeSet<String>> {
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())
}

0 comments on commit 1b36fa8

Please sign in to comment.