Skip to content

Commit

Permalink
Ensure virtual packages don't get included in package results
Browse files Browse the repository at this point in the history
  • Loading branch information
hwittenborn committed Sep 26, 2022
1 parent e257561 commit 22f251e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.6] - 2022-09-25
### Fixed
- Ensure virtual packages don't get included in package results.

## [0.9.5] - 2022-09-25
### Security
- Ensure `sudo` binary used for permission checks isn't one supplied by the user in the `PATH` variable.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mist"
version = "0.9.5"
version = "0.9.6"
authors = ["Hunter Wittenborn <[email protected]"]
description = "The official command-line interface for the makedeb Package Repository"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion makedeb/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# `-H 'MPR-Package: yes'` to your `makedeb` call if you want Mist to be able to
# automatically update itself.
pkgname=mist
pkgver=0.9.5
pkgver=0.9.6
pkgrel=1
pkgdesc='The official command-line interface for the makedeb Package Repository'
arch=('any')
Expand Down
23 changes: 21 additions & 2 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
use flate2::read::GzDecoder;
use rust_apt::{
cache::{Cache as AptCache, PackageSort},
package::Package,
progress::{AcquireProgress, InstallProgress},
tagfile::TagSection,
};
Expand Down Expand Up @@ -265,12 +266,30 @@ pub struct Cache {
}

impl Cache {
/// [`PackageSort::default`] isn't supposed to include virtual packages, but
/// it appears to be doing so on some systems. This checks for virtual
/// packages manually and excludes them.
pub fn get_nonvirtual_packages<'a>(
apt_cache: &'a AptCache,
sort: &'a PackageSort,
) -> Vec<Package<'a>> {
let mut vec = vec![];

for pkg in apt_cache.packages(sort) {
if pkg.candidate().is_some() {
vec.push(pkg);
}
}

vec
}

/// Create a new cache.
pub fn new(apt_cache: AptCache, mpr_cache: MprCache) -> Self {
// Package list.
let mut pkglist = Vec::new();

for pkg in apt_cache.packages(&PackageSort::default()) {
for pkg in Self::get_nonvirtual_packages(&apt_cache, &PackageSort::default()) {
let candidate = pkg.candidate().unwrap();

pkglist.push(CachePackage {
Expand Down Expand Up @@ -344,7 +363,7 @@ impl Cache {
let mut to_downgrade: Vec<String> = Vec::new();

// Report APT packages.
for pkg in self.apt_cache().packages(&PackageSort::default()) {
for pkg in Self::get_nonvirtual_packages(&self.apt_cache, &PackageSort::default()) {
let pkgname = pkg.name();
let apt_string = format!("{}{}", "apt/".to_string().green(), &pkgname);

Expand Down
2 changes: 1 addition & 1 deletion src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn remove(args: &clap::ArgMatches) {

// Remove any packages that are no longer needed.
if autoremove {
for pkg in cache.apt_cache().packages(&PackageSort::default()) {
for pkg in Cache::get_nonvirtual_packages(cache.apt_cache(), &PackageSort::default()) {
if pkg.is_auto_removable() {
pkg.mark_delete(purge).then_some(()).unwrap();
pkg.protect();
Expand Down
2 changes: 1 addition & 1 deletion src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn upgrade(args: &clap::ArgMatches) {
let mut mpr_pkgs = vec![];

// Check which APT packages need upgrading, and mark any for such if needed.
for pkg in cache.apt_cache().packages(&PackageSort::default()) {
for pkg in Cache::get_nonvirtual_packages(cache.apt_cache(), &PackageSort::default()) {
let pkgname = pkg.name();

if !mpr_only && pkg.is_upgradable(false) && let Some(pkg_control) = dpkg_map.get(&pkgname) && pkg_control.get("MPR-Package").is_none() {
Expand Down

0 comments on commit 22f251e

Please sign in to comment.