Skip to content

Commit

Permalink
Supporting all allowed checksums
Browse files Browse the repository at this point in the history
closes pulp#795
  • Loading branch information
adamsanaglo committed Aug 10, 2023
1 parent ccb3310 commit aae13a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion pulp_deb/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
FORCE_IGNORE_MISSING_PACKAGE_INDICES = False

APT_BY_HASH = True
APT_BY_HASH_CHECKSUM_TYPE = "sha256"
27 changes: 15 additions & 12 deletions pulp_deb/app/tasks/publishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from pulp_deb.app.constants import NO_MD5_WARNING_MESSAGE, CHECKSUM_TYPE_MAP

from pulp_deb.app.settings import APT_BY_HASH, APT_BY_HASH_CHECKSUM_TYPE
from pulp_deb.app.settings import APT_BY_HASH

import logging
from gettext import gettext as _
Expand Down Expand Up @@ -303,18 +303,20 @@ def finish(self):
gz_package_index.save()

# Generating metadata files using checksum
if APT_BY_HASH and APT_BY_HASH_CHECKSUM_TYPE in settings.ALLOWED_CONTENT_CHECKSUMS:
if APT_BY_HASH:
for path, index in (
(package_index_path, package_index),
(gz_package_index_path, gz_package_index),
):
hashed_index_path = _fetch_file_checksum(path, index)
hashed_index = PublishedMetadata.create_from_file(
publication=self.parent.publication,
file=File(open(path, "rb")),
relative_path=hashed_index_path,
)
hashed_index.save()
for allowed_checksum in settings.ALLOWED_CONTENT_CHECKSUMS:
if allowed_checksum in CHECKSUM_TYPE_MAP:
hashed_index_path = _fetch_file_checksum(path, index, allowed_checksum)
hashed_index = PublishedMetadata.create_from_file(
publication=self.parent.publication,
file=File(open(path, "rb")),
relative_path=hashed_index_path,
)
hashed_index.save()
# Done generating

self.parent.add_metadata(package_index)
Expand Down Expand Up @@ -356,6 +358,7 @@ def __init__(
self.release["Components"] = "" # Will be set later
if release.description != NULL_VALUE:
self.release["Description"] = release.description
self.release["Acquire-By-Hash"] = "yes" if APT_BY_HASH else "no"

for checksum_type, deb_field in CHECKSUM_TYPE_MAP.items():
if checksum_type in settings.ALLOWED_CONTENT_CHECKSUMS:
Expand Down Expand Up @@ -432,8 +435,8 @@ def _zip_file(file_path):
return gz_file_path


def _fetch_file_checksum(file_path, index):
h = getattr(index.contentartifact_set.first().artifact, APT_BY_HASH_CHECKSUM_TYPE)
checksum_type = CHECKSUM_TYPE_MAP[APT_BY_HASH_CHECKSUM_TYPE]
def _fetch_file_checksum(file_path, index, allowed_checksum):
h = getattr(index.contentartifact_set.first().artifact, allowed_checksum)
checksum_type = CHECKSUM_TYPE_MAP[allowed_checksum]
hashed_path = Path(file_path).parents[0] / "by-hash" / checksum_type / h
return hashed_path

0 comments on commit aae13a8

Please sign in to comment.