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

historydb: Prevent insertion of duplicate group packages #1798

Merged
merged 1 commit into from
Oct 24, 2024
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
12 changes: 9 additions & 3 deletions libdnf5/transaction/db/comps_group_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include <algorithm>
#include <memory>
#include <unordered_set>


namespace libdnf5::transaction {
Expand Down Expand Up @@ -92,11 +93,16 @@ static std::unique_ptr<libdnf5::utils::SQLite3::Statement> comps_group_package_i
void CompsGroupPackageDbUtils::comps_group_packages_insert(libdnf5::utils::SQLite3 & conn, CompsGroup & group) {
auto query_pkg_name_insert_if_not_exists = pkg_name_insert_if_not_exists_new_query(conn);
auto query = comps_group_package_insert_new_query(conn);
std::unordered_set<std::string> inserted_packages;
for (auto & pkg : group.get_packages()) {
// insert package name into 'pkg_name' table if not exists
pkg_name_insert_if_not_exists(*query_pkg_name_insert_if_not_exists, pkg.get_name());
query->bindv(
group.get_item_id(), pkg.get_name(), pkg.get_installed(), static_cast<int>(pkg.get_package_type()));
auto [pkg_name, inserted] = inserted_packages.emplace(pkg.get_name());
if (!inserted) {
// the package is duplicated in comps definition, skip it
continue;
}
pkg_name_insert_if_not_exists(*query_pkg_name_insert_if_not_exists, *pkg_name);
query->bindv(group.get_item_id(), *pkg_name, pkg.get_installed(), static_cast<int>(pkg.get_package_type()));
query->step();
pkg.set_id(query->last_insert_rowid());
query->reset();
Expand Down
Loading