Skip to content

Commit

Permalink
Download existing refs to the local storage when generating summaries
Browse files Browse the repository at this point in the history
closes #277
  • Loading branch information
lubosmj committed Aug 29, 2023
1 parent 464947b commit 1615a17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/277.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug that led to ignoring already imported refs in a repository when regenerating summaries.
22 changes: 20 additions & 2 deletions pulp_ostree/app/tasks/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from gettext import gettext

from asgiref.sync import sync_to_async

from pulpcore.plugin.models import Artifact, Repository, ProgressReport
from pulpcore.plugin.stages import (
ArtifactSaver,
Expand All @@ -16,7 +18,9 @@

from pulp_ostree.app.models import (
OstreeCommit,
OstreeRef,
OstreeConfig,
OstreeObject,
OstreeObjectType,
OstreeSummary,
)
Expand Down Expand Up @@ -44,7 +48,9 @@ def import_all_refs_and_commits(artifact_pk, repository_pk, repository_name):
tarball_artifact = Artifact.objects.get(pk=artifact_pk)
repository = Repository.objects.get(pk=repository_pk)
compute_delta = repository.cast().compute_delta
first_stage = OstreeImportAllRefsFirstStage(tarball_artifact, repository_name, compute_delta)
first_stage = OstreeImportAllRefsFirstStage(
tarball_artifact, repository_name, compute_delta, repository
)
dv = OstreeImportDeclarativeVersion(first_stage, repository)
return dv.create()

Expand Down Expand Up @@ -277,11 +283,12 @@ class OstreeImportAllRefsFirstStage(
):
"""A first stage of the OSTree importing pipeline that handles creation of content units."""

def __init__(self, tarball_artifact, repo_name, compute_delta):
def __init__(self, tarball_artifact, repo_name, compute_delta, repository):
"""Initialize class variables used for parsing OSTree objects."""
super().__init__(repo_name)
self.tarball_artifact = tarball_artifact
self.compute_delta = compute_delta
self.repository = repository

self.create_object_dc_func = self.create_dc

Expand Down Expand Up @@ -326,6 +333,17 @@ async def run(self):

await self.submit_ref_objects()

latest_version = await self.repository.alatest_version()
refs = await sync_to_async(latest_version.get_content)(OstreeRef.objects)
async for ref in refs:
# consider already uploaded refs to correctly regenerate the summary
file_path = os.path.join(self.repo_path, "refs", "heads", ref.name)
ref_file = await ref._artifacts.aget()
copy_to_local_storage(ref_file.file, file_path)

commit = await OstreeCommit.objects.aget(refs_commit=ref)
await self.copy_from_storage_to_tmp(commit, OstreeObject.objects.none())

self.repo.regenerate_summary()
await self.submit_metafile_object("summary", OstreeSummary())

Expand Down

0 comments on commit 1615a17

Please sign in to comment.