Skip to content

Commit

Permalink
Merge pull request #1021 from ATIX-AG/fix_dup_package_logging
Browse files Browse the repository at this point in the history
Fix DEBUG logging of duplicate pakcages

(cherry picked from commit adabeae)
  • Loading branch information
quba42 authored and patchback[bot] committed Feb 27, 2024
1 parent 3cd42a7 commit 39e6379
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/994.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed DEBUG logging of prohibited duplicate packages.
41 changes: 35 additions & 6 deletions pulp_deb/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ class Meta:
unique_together = (("repository", "release_distribution"),)


def find_dist_components(package_ids, content_set):
"""
Given a list of package_ids and a content_set, this function will find all distribution-
component combinations that exist for the given package_ids within the given content_set.
Returns a set of strings, e.g.: "buster main".
"""
# PackageReleaseComponents:
package_prc_qs = PackageReleaseComponent.objects.filter(package__in=package_ids).only("pk")
prc_content_qs = content_set.filter(pk__in=package_prc_qs)
prc_qs = PackageReleaseComponent.objects.filter(pk__in=prc_content_qs.only("pk"))

# ReleaseComponents:
distribution_components = set()
for prc in prc_qs.select_related("release_component").iterator():
distribution = prc.release_component.distribution
component = prc.release_component.component
distribution_components.add(distribution + " " + component)

return distribution_components


def handle_duplicate_packages(new_version):
"""
pulpcore's remove_duplicates does not work for .deb packages, since identical duplicate
Expand Down Expand Up @@ -148,19 +170,26 @@ def handle_duplicate_packages(new_version):
added_checksum_unique = package_qs_added.distinct(*repo_key_fields, "sha256")

if added_unique.count() < added_checksum_unique.count():
package_qs_added_duplicates = added_checksum_unique.difference(added_unique)
if log.isEnabledFor(logging.DEBUG):
message = _(
"New repository version contains multiple packages with '{}', but differing "
"checksum!"
'New repository version is trying to add different versions, of package "{}", '
'to each of the following distribution-component combinations "{}"!'
)
for package_fields in package_qs_added_duplicates.values(*repo_key_fields):
log.debug(message.format(package_fields))
package_qs_added_dups = added_checksum_unique.difference(added_unique)
for package_fields in package_qs_added_dups.values(*repo_key_fields, "sha256"):
package_fields.pop("sha256")
duplicate_package_ids = package_qs_added.filter(**package_fields).only("pk")
distribution_components = find_dist_components(
duplicate_package_ids, content_qs_added
)
log.debug(message.format(package_fields, distribution_components))

message = _(
"Cannot create repository version since there are newly added packages with the "
"same name, version, and architecture, but a different checksum. If the log level "
"is DEBUG, you can find a list of affected packages in the Pulp log."
"is DEBUG, you can find a list of affected packages in the Pulp log. You can often "
"work around this issue by restricting syncs to only those distirbution component "
"combinations, that do not contain colliding duplicates!"
)
raise ValueError(message)

Expand Down

0 comments on commit 39e6379

Please sign in to comment.