Skip to content
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

versionlock: Fix wildcards handling in add command #2009

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions dnf5/commands/versionlock/versionlock_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,35 @@ void VersionlockAddCommand::run() {
std::cerr << libdnf5::utils::sformat(_("No package found for \"{}\"."), spec) << std::endl;
continue;
}
libdnf5::rpm::PackageQuery installed_query(query);
installed_query.filter_installed();
if (!installed_query.empty()) {
// if spec is installed, add only installed version
query = installed_query;
}

std::unordered_set<std::string> versions{};
// The spec can resolve to multiple package names. Handle each name in
// the query separately.
std::set<std::string> package_names;
for (const auto & pkg : query) {
auto evr = pkg.get_evr();
if (versions.contains(evr)) {
continue;
package_names.emplace(pkg.get_name());
}
for (const auto & name : package_names) {
libdnf5::rpm::PackageQuery name_query(query);
name_query.filter_name(name);
libdnf5::rpm::PackageQuery installed_query(name_query);
installed_query.filter_installed();
if (!installed_query.empty()) {
// if spec is installed, add only installed version
name_query = installed_query;
}
versions.emplace(evr);
if (lock_version(vl_config, pkg, comment)) {
std::cout << libdnf5::utils::sformat(_("Adding versionlock on \"{0} = {1}\"."), pkg.get_name(), evr)
<< std::endl;
} else {
std::cerr << libdnf5::utils::sformat(_("Package \"{}\" is already locked."), spec) << std::endl;

std::unordered_set<std::string> versions{};
for (const auto & pkg : name_query) {
auto evr = pkg.get_evr();
if (versions.contains(evr)) {
continue;
}
versions.emplace(evr);
if (lock_version(vl_config, pkg, comment)) {
std::cout << libdnf5::utils::sformat(_("Adding versionlock on \"{0} = {1}\"."), pkg.get_name(), evr)
<< std::endl;
} else {
std::cerr << libdnf5::utils::sformat(_("Package \"{}\" is already locked."), spec) << std::endl;
}
}
}
}
Expand Down
Loading