-
Notifications
You must be signed in to change notification settings - Fork 26
Upstream some Alpm
methods
#30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fosskers
wants to merge
9
commits into
archlinux:master
Choose a base branch
from
fosskers:colin/alpm-extensions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
97e8e49
feat(utils): resurrect the `AlpmExt` trait
fosskers b7e35e1
feat(utils): upstream a few common functions
fosskers 7c4e9ab
lint: minor cleanup
fosskers 7dc220d
fix: correct the module tree
fosskers 21c36c2
feat(utils): drop unneeded functionality
fosskers 1fc2aa3
feat(utils): rework module structure
fosskers cf070a1
feat(utils): revive `AlpmExt` yet again
fosskers 1cef5c6
lint: silence `cargo doc` warning
fosskers 4be3dee
lint: appease Clippy
fosskers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,74 @@ | ||
use crate::depends::satisfies_ver; | ||
//! Extension methods for the [`Alpm`] type. | ||
|
||
use alpm::{Alpm, Result, Package, Depend}; | ||
use crate::DbListExt; | ||
use alpm::{Alpm, AlpmList, Db, IntoIter, Package}; | ||
|
||
/// Extension methods for [`Alpm`] which aren't critical enough to live in the | ||
/// main crate, directly within `Alpm`. | ||
pub trait AlpmExt { | ||
fn find_local_satisfier<S: Into<String>>(&self, pkg: S) -> Result<Option<Package>>; | ||
/// An iterator of [`Package`]s that are found in "sync databases", | ||
/// typically registered in one's `pacman.conf`. | ||
fn native_packages(&self) -> NativePkgs<'_>; | ||
|
||
/// The opposite of [`AlpmExt::native_packages`]; installed packages that | ||
/// aren't found in any registered "sync database". | ||
fn foreign_packages(&self) -> ForeignPkgs<'_>; | ||
} | ||
|
||
impl AlpmExt for Alpm { | ||
fn find_local_satisfier<S: Into<String>>(&self, pkg: S) -> Result<Option<Package>> { | ||
let localdb = self.localdb(); | ||
let pkg = pkg.into(); | ||
fn native_packages(&self) -> NativePkgs<'_> { | ||
NativePkgs::new(self) | ||
} | ||
|
||
fn foreign_packages(&self) -> ForeignPkgs<'_> { | ||
ForeignPkgs::new(self) | ||
} | ||
} | ||
|
||
/// [`Package`]s that are found in registered "sync databases". | ||
pub struct NativePkgs<'a> { | ||
local: IntoIter<'a, Package<'a>>, | ||
sync: AlpmList<'a, Db<'a>>, | ||
} | ||
|
||
impl<'a> NativePkgs<'a> { | ||
fn new(alpm: &'a Alpm) -> NativePkgs<'a> { | ||
let local = alpm.localdb().pkgs().into_iter(); | ||
let sync = alpm.syncdbs(); | ||
|
||
NativePkgs { local, sync } | ||
} | ||
} | ||
|
||
impl<'a> Iterator for NativePkgs<'a> { | ||
type Item = Package<'a>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
let s = self.sync; | ||
self.local.find(|p| s.pkg(p.name()).is_ok()) | ||
} | ||
} | ||
|
||
/// Installed [`Package`]s that are _not_ found in registered "sync databases". | ||
pub struct ForeignPkgs<'a> { | ||
local: IntoIter<'a, Package<'a>>, | ||
sync: AlpmList<'a, Db<'a>>, | ||
} | ||
|
||
impl<'a> ForeignPkgs<'a> { | ||
fn new(alpm: &'a Alpm) -> ForeignPkgs<'a> { | ||
let local = alpm.localdb().pkgs().into_iter(); | ||
let sync = alpm.syncdbs(); | ||
|
||
ForeignPkgs { local, sync } | ||
} | ||
} | ||
|
||
if let Ok(alpm_pkg) = localdb.pkg(&pkg) { | ||
if satisfies_ver(&Depend::new(&pkg), alpm_pkg.version()) { | ||
return Ok(Some(alpm_pkg)); | ||
} | ||
} | ||
impl<'a> Iterator for ForeignPkgs<'a> { | ||
type Item = Package<'a>; | ||
|
||
return Ok(localdb.pkgs()?.find_satisfier(pkg)); | ||
fn next(&mut self) -> Option<Self::Item> { | ||
let s = self.sync; | ||
self.local.find(|p| s.pkg(p.name()).is_err()) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you got some custom cargo fmt config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't, but the last changes to these lines occurred in 2019, so there's a chance that
rustfmt
changed since then.