Skip to content

Commit

Permalink
Repoquery: Add --duplicates option
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura committed Nov 30, 2022
1 parent bb12546 commit 9ef25f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 21 additions & 3 deletions dnf5/commands/repoquery/repoquery.cpp
Expand Up @@ -101,6 +101,14 @@ void RepoqueryCommand::set_argument_parser() {

info->add_conflict_argument(*nevra);

duplicates = std::make_unique<libdnf::cli::session::BoolOption>(
*this,
"duplicates",
'\0',
"Limit the resulting set to installed duplicate packages (i.e. more package versions for the same name and "
"architecture). Installonly packages are excluded from this set.",
false);

advisory_name = std::make_unique<AdvisoryOption>(*this);
advisory_security = std::make_unique<SecurityOption>(*this);
advisory_bugfix = std::make_unique<BugfixOption>(*this);
Expand All @@ -120,7 +128,8 @@ void RepoqueryCommand::set_argument_parser() {
void RepoqueryCommand::configure() {
auto & context = get_context();
context.update_repo_load_flags_from_specs(pkg_specs);
context.set_load_system_repo(installed_option->get_value());
only_system_repo_needed = installed_option->get_value() || duplicates->get_value();
context.set_load_system_repo(only_system_repo_needed);
bool updateinfo_needed = advisory_name->get_value().empty() || advisory_security->get_value() ||
advisory_bugfix->get_value() || advisory_enhancement->get_value() ||
advisory_newpackage->get_value() || advisory_severity->get_value().empty() ||
Expand All @@ -130,13 +139,13 @@ void RepoqueryCommand::configure() {
context.get_available_repos_load_flags() | libdnf::repo::LoadFlags::UPDATEINFO);
}
context.set_load_available_repos(
available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !installed_option->get_value()
available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !only_system_repo_needed
? Context::LoadAvailableRepos::ENABLED
: Context::LoadAvailableRepos::NONE);
}

void RepoqueryCommand::load_additional_packages() {
if (available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !installed_option->get_value()) {
if (available_option->get_priority() >= libdnf::Option::Priority::COMMANDLINE || !only_system_repo_needed) {
cmdline_packages = get_context().add_cmdline_packages(pkg_file_paths);
}
}
Expand All @@ -161,6 +170,15 @@ void RepoqueryCommand::run() {
full_package_query.filter_advisories(advisories.value(), libdnf::sack::QueryCmp::GTE);
}

if (duplicates->get_value()) {
auto & cfg_main = ctx.base.get_config();
const auto & installonly_packages = cfg_main.installonlypkgs().get_value();
auto installonly_query = full_package_query;
installonly_query.filter_provides(installonly_packages, libdnf::sack::QueryCmp::GLOB);
full_package_query -= installonly_query;
full_package_query.filter_duplicates();
}

if (pkg_specs.empty() && pkg_file_paths.empty()) {
result_pset |= full_package_query;
} else {
Expand Down
4 changes: 4 additions & 0 deletions dnf5/commands/repoquery/repoquery.hpp
Expand Up @@ -43,6 +43,8 @@ class RepoqueryCommand : public Command {
void run() override;

private:
bool only_system_repo_needed = false;

libdnf::OptionBool * available_option{nullptr};
libdnf::OptionBool * installed_option{nullptr};
libdnf::OptionBool * info_option{nullptr};
Expand All @@ -51,6 +53,8 @@ class RepoqueryCommand : public Command {
std::vector<std::string> pkg_file_paths;
std::vector<libdnf::rpm::Package> cmdline_packages;

std::unique_ptr<libdnf::cli::session::BoolOption> duplicates{nullptr};

std::unique_ptr<AdvisoryOption> advisory_name{nullptr};
std::unique_ptr<SecurityOption> advisory_security{nullptr};
std::unique_ptr<BugfixOption> advisory_bugfix{nullptr};
Expand Down

0 comments on commit 9ef25f8

Please sign in to comment.