Skip to content

Commit

Permalink
getting checksum from artifact model
Browse files Browse the repository at this point in the history
closes pulp#795
  • Loading branch information
adamsanaglo committed Aug 10, 2023
1 parent d68c99b commit 5c9ac13
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pulp_deb/app/tasks/publishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,15 @@ def finish(self):

# Generating metadata files using checksum
if APT_BY_HASH and APT_BY_HASH_CHECKSUM_TYPE in settings.ALLOWED_CONTENT_CHECKSUMS:
for path in (package_index_path, gz_package_index_path):
hashed_index_path = _create_checksum_file(path)
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(hashed_index_path, "rb")),
file=File(open(path, "rb")),
relative_path=hashed_index_path,
)
hashed_index.save()
# Done generating
Expand Down Expand Up @@ -438,8 +442,14 @@ def _checksum_file(path):


def _create_checksum_file(file_path):
by_hash_path = Path(file_path).parents[0] / "byhash"
by_hash_path = Path(file_path).parents[0] / "by-hash" / APT_BY_HASH_CHECKSUM_TYPE
by_hash_path.mkdir(parents=True, exist_ok=True)
hashed_path = by_hash_path / _checksum_file(file_path)
shutil.copyfile(file_path, hashed_path)
return hashed_path


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

0 comments on commit 5c9ac13

Please sign in to comment.