Skip to content

Commit

Permalink
Resolving aptbyhash pr comments
Browse files Browse the repository at this point in the history
closes pulp#795
  • Loading branch information
adamsanaglo committed Jul 18, 2023
1 parent 91281e3 commit 5968ac0
Show file tree
Hide file tree
Showing 84 changed files with 34 additions and 181 deletions.
3 changes: 2 additions & 1 deletion CHANGES/795.feature
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Mitigating the Hash Sum Mismatch error by generating additional metadata files named by checksum
Mitigating the Hash Sum Mismatch error in debian repos by generating additional metadata files named by checksum.
Wiki of the feature: https://wiki.ubuntu.com/AptByHash
50 changes: 0 additions & 50 deletions pulp_deb.egg-info/PKG-INFO

This file was deleted.

93 changes: 0 additions & 93 deletions pulp_deb.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion pulp_deb.egg-info/dependency_links.txt

This file was deleted.

2 changes: 0 additions & 2 deletions pulp_deb.egg-info/entry_points.txt

This file was deleted.

2 changes: 0 additions & 2 deletions pulp_deb.egg-info/requires.txt

This file was deleted.

1 change: 0 additions & 1 deletion pulp_deb.egg-info/top_level.txt

This file was deleted.

Binary file removed pulp_deb/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed pulp_deb/app/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed pulp_deb/app/__pycache__/constants.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file removed pulp_deb/app/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file removed pulp_deb/app/__pycache__/urls.cpython-38.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion pulp_deb/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@

# Represents null values since nulls can't be used in unique indexes in postgres < 15
NULL_VALUE = "__!!!NULL VALUE!!!__"
APT_BY_HASH = True
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed pulp_deb/app/models/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed pulp_deb/app/models/__pycache__/remote.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed pulp_deb/app/schema/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions pulp_deb/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

FORBIDDEN_CHECKSUM_WARNINGS = True
FORCE_IGNORE_MISSING_PACKAGE_INDICES = False
APT_BY_HASH = True
APT_BY_HASH_CHECKSUM_TYPE = "sha256"
Binary file removed pulp_deb/app/tasks/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file removed pulp_deb/app/tasks/__pycache__/copy.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
60 changes: 30 additions & 30 deletions pulp_deb/app/tasks/publishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import shutil
from contextlib import suppress
from pathlib import Path
import hashlib

from datetime import datetime, timezone
Expand Down Expand Up @@ -35,11 +36,9 @@

from pulp_deb.app.serializers import Package822Serializer

from pulp_deb.app.constants import (
NO_MD5_WARNING_MESSAGE,
CHECKSUM_TYPE_MAP,
APT_BY_HASH
)
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

import logging
from gettext import gettext as _
Expand Down Expand Up @@ -99,7 +98,7 @@ def publish(repository_version_pk, simple=False, structured=False, signing_servi
structured=structured,
)
)

with tempfile.TemporaryDirectory("."):
with AptPublication.create(repo_version, pass_through=False) as publication:
publication.simple = simple
Expand Down Expand Up @@ -219,7 +218,7 @@ def publish(repository_version_pk, simple=False, structured=False, signing_servi
for release_helper in release_helpers:
release_helper.save_signed_metadata()

log.info(_("Publication: {publication} createddddd").format(publication=publication.pk))
log.info(_("Publication: {publication} created").format(publication=publication.pk))


async def _concurrently_sign_metadata(release_helpers):
Expand Down Expand Up @@ -281,34 +280,26 @@ def finish(self):
)
package_index.save()

# Generating metadata files using checksum
if APT_BY_HASH:
by_hash_path = os.path.join(os.path.dirname(package_index_path), 'byhash')
if not os.path.exists(by_hash_path):
os.makedirs(by_hash_path)
package_hashed_index_path = os.path.join(by_hash_path, _sha256sum(package_index_path))
shutil.copyfile(package_index_path, package_hashed_index_path)
package_hashed_index = PublishedMetadata.create_from_file(
publication=self.parent.publication, file=File(open(package_hashed_index_path, "rb"))
)
package_hashed_index.save()
# Done generating

gz_package_index = PublishedMetadata.create_from_file(
publication=self.parent.publication, file=File(open(gz_package_index_path, "rb"))
)
gz_package_index.save()

# Generating metadata files using checksum
if APT_BY_HASH:
by_hash_path = os.path.join(os.path.dirname(gz_package_index_path), 'byhash')
if not os.path.exists(by_hash_path):
os.makedirs(by_hash_path)
gz_package_hashed_index_path = os.path.join(by_hash_path, _sha256sum(gz_package_index_path))
shutil.copyfile(gz_package_index_path, gz_package_hashed_index_path)
if APT_BY_HASH and APT_BY_HASH_CHECKSUM_TYPE in ALLOWED_CONTENT_CHECKSUMS:
package_hashed_index_path = _create_checksum_file(package_index_path)
package_hashed_index = PublishedMetadata.create_from_file(
publication=self.parent.publication,
file=File(open(package_hashed_index_path, "rb")),
)
package_hashed_index.save()

gz_package_hashed_index_path = _create_checksum_file(gz_package_index_path)
gz_package_hashed_index = PublishedMetadata.create_from_file(
publication=self.parent.publication, file=File(open(gz_package_hashed_index_path, "rb"))
publication=self.parent.publication,
file=File(open(gz_package_hashed_index_path, "rb")),
)

gz_package_hashed_index.save()
# Done generating

Expand Down Expand Up @@ -426,9 +417,18 @@ def _zip_file(file_path):
shutil.copyfileobj(f_in, f_out)
return gz_file_path

def _sha256sum(path):
h = hashlib.sha256()

def _checksum_file(path):
h = hashlib.new(APT_BY_HASH_CHECKSUM_TYPE)
with open(path, "rb") as f:
for line in f:
h.update(line)
return h.hexdigest()
return h.hexdigest()


def _create_checksum_file(file_path):
by_hash_path = Path(file_path).parents[0] / "byhash"
by_hash_path.mkdir(parents=True, exists_ok=True)
hashed_path = by_hash_path / _checksum_file(file_path)
shutil.copyfile(file_path, hashed_path)
return hashed_path
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed pulp_deb/app/viewsets/__pycache__/remote.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file removed pulp_deb/tests/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 5968ac0

Please sign in to comment.