Skip to content

Commit 21c36c2

Browse files
committed
feat(utils): drop unneeded functionality
And rename a few functions.
1 parent 7dc220d commit 21c36c2

File tree

1 file changed

+3
-50
lines changed

1 file changed

+3
-50
lines changed

alpm-utils/src/alpm.rs

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
11
//! Extension methods for the [`Alpm`] type.
22
3-
use crate::depends::satisfies_ver;
43
use crate::DbListExt;
5-
use alpm::{Alpm, Depend, Package, PackageReason, SigLevel};
6-
use std::path::Path;
7-
8-
/// Extension methods to the [`Alpm`] type.
9-
pub trait AlpmExt {
10-
/// Try to find a [`Package`] that satisfies a given dependency.
11-
fn find_local_satisfier<S>(&self, pkg: S) -> Option<Package<'_>>
12-
where
13-
S: Into<String>;
14-
}
15-
16-
impl AlpmExt for Alpm {
17-
fn find_local_satisfier<S>(&self, pkg: S) -> Option<Package<'_>>
18-
where
19-
S: Into<String>,
20-
{
21-
let localdb = self.localdb();
22-
let pkg = pkg.into();
23-
24-
match localdb.pkg(pkg.as_str()) {
25-
Ok(alpm_pkg) if satisfies_ver(Depend::new(pkg.as_str()), alpm_pkg.version()) => {
26-
Some(alpm_pkg)
27-
}
28-
_ => localdb.pkgs().find_satisfier(pkg),
29-
}
30-
}
31-
}
32-
33-
/// All orphaned packages.
34-
///
35-
/// An orphan is a package that was installed as a dependency, but whose parent
36-
/// package is no longer installed.
37-
pub fn orphans(alpm: &Alpm) -> impl Iterator<Item = Package<'_>> {
38-
alpm.localdb().pkgs().into_iter().filter(|p| {
39-
p.reason() == PackageReason::Depend
40-
&& p.required_by().is_empty()
41-
&& p.optional_for().is_empty()
42-
})
43-
}
4+
use alpm::{Alpm, Package};
445

456
/// All official packages.
46-
pub fn officials(alpm: &Alpm) -> impl Iterator<Item = Package<'_>> {
7+
pub fn native_packages(alpm: &Alpm) -> impl Iterator<Item = Package<'_>> {
478
let syncs = alpm.syncdbs();
489

4910
alpm.localdb()
@@ -53,19 +14,11 @@ pub fn officials(alpm: &Alpm) -> impl Iterator<Item = Package<'_>> {
5314
}
5415

5516
/// All foreign packages as an `Iterator`.
56-
pub fn foreigns(alpm: &Alpm) -> impl Iterator<Item = Package<'_>> {
17+
pub fn foreign_packages(alpm: &Alpm) -> impl Iterator<Item = Package<'_>> {
5718
let syncs = alpm.syncdbs();
5819

5920
alpm.localdb()
6021
.pkgs()
6122
.into_iter()
6223
.filter(move |p| syncs.pkg(p.name()).is_err())
6324
}
64-
65-
/// Does the given `Path` point to a valid tarball that can can loaded by ALPM?
66-
pub fn is_valid_package(alpm: &Alpm, path: &Path) -> bool {
67-
match path.to_str() {
68-
None => false,
69-
Some(p) => path.exists() && alpm.pkg_load(p, true, SigLevel::USE_DEFAULT).is_ok(),
70-
}
71-
}

0 commit comments

Comments
 (0)