From 9ab74934591a5472bf39e1a37ddf317e7c80fcb8 Mon Sep 17 00:00:00 2001 From: Lubos Mjachky Date: Mon, 28 Aug 2023 21:47:29 +0200 Subject: [PATCH] Check for existing parent commits in import-all closes #279 (cherry picked from commit 38f6f5fc98a68127e86b702a19aa8ed239d12a2b) --- CHANGES/279.bugfix | 1 + pulp_ostree/app/tasks/importing.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 CHANGES/279.bugfix diff --git a/CHANGES/279.bugfix b/CHANGES/279.bugfix new file mode 100644 index 00000000..38fff3b2 --- /dev/null +++ b/CHANGES/279.bugfix @@ -0,0 +1 @@ +Made the import facility to accept tarballs with already imported parent commits. diff --git a/pulp_ostree/app/tasks/importing.py b/pulp_ostree/app/tasks/importing.py index 7accbc65..7123cb2f 100644 --- a/pulp_ostree/app/tasks/importing.py +++ b/pulp_ostree/app/tasks/importing.py @@ -117,9 +117,17 @@ async def parse_ref(self, name, ref_commit_checksum, has_referenced_parent=False # and this state is still considered valid return parent_checksum, ref_commit_dc else: - raise ValueError( - gettext("The parent commit '{}' could not be loaded").format(parent_checksum) - ) + try: + parent_commit = await OstreeCommit.objects.aget(checksum=parent_checksum) + except OstreeCommit.DoesNotExist: + raise ValueError( + gettext("The parent commit '{}' could not be loaded").format( + parent_checksum + ) + ) + else: + await self.copy_from_storage_to_tmp(parent_commit, parent_commit.objs) + _, parent_commit, _ = self.repo.load_commit(parent_checksum) return await self.load_next_commits(parent_commit, parent_checksum, has_referenced_parent) @@ -323,9 +331,10 @@ async def run(self): if self.compute_delta: num_of_parsed_commits = len(self.commit_dcs) - parent_commit = await OstreeCommit.objects.aget( + commit = await OstreeCommit.objects.select_related("parent_commit").aget( checksum=ref_commit_checksum - ).parent_commit + ) + parent_commit = commit.parent_commit if parent_commit and num_of_parsed_commits == 1: await self.copy_from_storage_to_tmp(parent_commit, parent_commit.objs) await self.compute_static_delta(