Skip to content

Commit

Permalink
historydb: Prevent insertion of duplicate group packages
Browse files Browse the repository at this point in the history
When a package is included in a comps group multiple times, dnf5
attempts to insert that package multiple times into the
`comps_group_package table` of the transaction history database. However,
the table enforces a unique constraint on the (group_id, name_id) tuple.
This results in terminating dnf5 process.

This patch modifies the CompsGroupPackageDbUtils::comps_group_packages_insert()
method to track which packages have already been inserted and skip
duplicates.

Here is an example of such group with duplicated packages from rpmfusion
repository (see the `libavcodec-freeworld` package):

<group>
  <id>multimedia</id>
  <name>Multimedia</name>
  <description>Audio/video framework common to desktops</description>
  <default>false</default>
  <uservisible>false</uservisible>
  <packagelist>
    <packagereq>gstreamer1-plugins-bad-freeworld</packagereq>
    <packagereq>gstreamer1-plugins-ugly</packagereq>
    <packagereq type="conditional" requires="chromium">libavcodec-freeworld</packagereq>
    <packagereq type="conditional" requires="firefox">libavcodec-freeworld</packagereq>
    <packagereq type="conditional" requires="libavcodec-free">libavcodec-freeworld</packagereq>
    <packagereq type="conditional" requires="libheif">libheif-freeworld</packagereq>
    <packagereq type="conditional" requires="pipewire">pipewire-codec-aptx</packagereq>
    <packagereq type="conditional" requires="qt5-qtwebengine">qt5-qtwebengine-freeworld</packagereq>
    <packagereq type="conditional" requires="vlc-libs">vlc-plugins-freeworld</packagereq>
  </packagelist>
</group>

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2263762
  • Loading branch information
m-blaha committed Oct 23, 2024
1 parent bce0365 commit cb4c6b5
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit cb4c6b5

Please sign in to comment.