Skip to content

Commit

Permalink
PackageQuery: add filter_installonly
Browse files Browse the repository at this point in the history
This allows it to be easily reused.
  • Loading branch information
kontura authored and j-mracek committed Oct 17, 2023
1 parent a7b4f0f commit eaf6a19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
15 changes: 6 additions & 9 deletions dnf5/commands/repoquery/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,6 @@ static libdnf5::rpm::PackageSet resolve_nevras_to_packges(
return resolved_nevras_set;
}

static libdnf5::rpm::PackageQuery get_installonly_query(libdnf5::Base & base) {
auto & cfg_main = base.get_config();
const auto & installonly_packages = cfg_main.get_installonlypkgs_option().get_value();
libdnf5::rpm::PackageQuery installonly_query(base);
installonly_query.filter_provides(installonly_packages, libdnf5::sack::QueryCmp::GLOB);
return installonly_query;
}

void RepoqueryCommand::run() {
auto & ctx = get_context();
Expand Down Expand Up @@ -539,7 +532,9 @@ void RepoqueryCommand::run() {
}

if (duplicates->get_value()) {
result_query -= get_installonly_query(ctx.base);
libdnf5::rpm::PackageQuery installonly_query(ctx.base, flags, false);
installonly_query.filter_installonly();
result_query -= installonly_query;
result_query.filter_duplicates();
}

Expand All @@ -548,7 +543,9 @@ void RepoqueryCommand::run() {
}

if (installonly->get_value()) {
result_query &= get_installonly_query(ctx.base);
libdnf5::rpm::PackageQuery installonly_query(ctx.base, flags, false);
installonly_query.filter_installonly();
result_query &= installonly_query;
}

// APPLY FILTERS THAT REQUIRE BOTH INSTALLED AND AVAILABLE PACKAGES TO BE LOADED
Expand Down
5 changes: 5 additions & 0 deletions include/libdnf5/rpm/package_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,11 @@ class PackageQuery : public PackageSet {
/// @return Groups of one or more interdependent leaf packages.
std::vector<std::vector<Package>> filter_leaves_groups();

/// Filter installonly packages.
///
/// Filter packages that provide a capability that matches with any value in installonlypkgs configuration option.
void filter_installonly();

private:
std::vector<std::vector<Package>> filter_leaves(bool return_grouped_leaves);

Expand Down
5 changes: 5 additions & 0 deletions libdnf5/rpm/package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2822,5 +2822,10 @@ void PackageQuery::filter_extras(const bool exact_evr) {
}
}

void PackageQuery::filter_installonly() {
auto & cfg_main = p_impl->base->get_config();
const auto & installonly_packages = cfg_main.get_installonlypkgs_option().get_value();
filter_provides(installonly_packages, libdnf5::sack::QueryCmp::GLOB);
}

} // namespace libdnf5::rpm
3 changes: 1 addition & 2 deletions libdnf5/rpm/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ void Transaction::fill(const base::Transaction & transaction) {
// Used to detect installation of a installonly package with lower version
// that is currently installed.
std::map<std::string, libdnf5::rpm::Package> installonly_versions;
const auto & installonlypkgs = base->get_config().get_installonlypkgs_option().get_value();
rpm::PackageQuery installonly_query(base);
installonly_query.filter_installed();
installonly_query.filter_latest_evr();
installonly_query.filter_provides(installonlypkgs, libdnf5::sack::QueryCmp::GLOB);
installonly_query.filter_installonly();
for (const auto & pkg : installonly_query) {
installonly_versions.insert(std::make_pair(pkg.get_name(), pkg));
}
Expand Down

0 comments on commit eaf6a19

Please sign in to comment.