From cb136fe9f0532999cc51c02aa461ec3b68ac7957 Mon Sep 17 00:00:00 2001 From: Nikola Forró Date: Jan 30 2025 09:22:52 +0000 Subject: [PATCH 1/2] Make lookaside cache work with SIG dist-git using "modern" layout Signed-off-by: Nikola Forró --- diff --git a/src/centpkg/__init__.py b/src/centpkg/__init__.py index 185ab54..3667b98 100644 --- a/src/centpkg/__init__.py +++ b/src/centpkg/__init__.py @@ -180,11 +180,21 @@ class Commands(Commands): @cached_property def lookasidecache(self): if self.layout.sources_file_template == "sources": - return StreamLookasideCache( - self.lookasidehash, - self.lookaside, - self.lookaside_cgi, - ) + if self.distgitdir.sigbranch: + return SIGLookasideCache( + self.lookasidehash, + self.lookaside, + self.lookaside_cgi, + self.repo_name, + branch=None, + client_cert=os.path.expanduser("~/.centos.cert"), + ) + else: + return StreamLookasideCache( + self.lookasidehash, + self.lookaside, + self.lookaside_cgi, + ) else: if self.distgitdir.sigbranch: return SIGLookasideCache( diff --git a/src/centpkg/lookaside.py b/src/centpkg/lookaside.py index 4ad964c..8023918 100644 --- a/src/centpkg/lookaside.py +++ b/src/centpkg/lookaside.py @@ -240,7 +240,10 @@ class SIGLookasideCache(CGILookasideCache): self.branch = branch def get_download_url(self, name, filename, hash, hashtype=None, **kwargs): - download_path = "%(name)s/%(branch)s/%(hash)s" + if self.branch: + download_path = "%(name)s/%(branch)s/%(hash)s" + else: + download_path = self.download_path if "/" in name: real_name = name.split("/")[-1] else: @@ -264,6 +267,9 @@ class SIGLookasideCache(CGILookasideCache): :param str filename: The name of the file to check for. :param str hash: The known good hash of the file. """ + if not self.branch: + return super(SIGLookasideCache, self).remote_file_exists_head( + name, filename, hash, self.hashtype) # RHEL 7 ships pycurl that does not accept unicode. When given unicode # type it would explode with "unsupported second type in tuple". Let's @@ -325,7 +331,7 @@ class SIGLookasideCache(CGILookasideCache): self.log.debug(output) raise UploadError("Error checking for %s at %s" % (filename, self.upload_url)) - def upload(self, name, filepath, hash): + def upload(self, name, filename, hash, offline=False): """Upload a source file :param str name: The name of the module. (usually the name of the SRPM) @@ -334,6 +340,15 @@ class SIGLookasideCache(CGILookasideCache): :param str filepath: The full path to the file to upload. :param str hash: The known good hash of the file. """ + if "/" in name: + real_name = name.split("/")[-1] + else: + real_name = name + + if not self.branch: + return super(SIGLookasideCache, self).upload( + real_name, filename, hash) + filename = os.path.basename(filepath) if self.remote_file_exists(name, filename, hash): @@ -342,7 +357,7 @@ class SIGLookasideCache(CGILookasideCache): self.log.info("Uploading: %s", filepath) post_data = [ - ("name", name), + ("name", real_name), ("%ssum" % self.hashtype, hash), ("file", (pycurl.FORM_FILE, filepath)), ] From e4c02c21ff5dbac663b3c3f57bdf3431bec4595b Mon Sep 17 00:00:00 2001 From: Nikola Forró Date: Jan 30 2025 09:32:50 +0000 Subject: [PATCH 2/2] Relax SIG branch matching Make the regex match also branches with a custom suffix, such as branches created by Packit propose-downstream or pull-from-upstream. Signed-off-by: Nikola Forró --- diff --git a/src/centpkg/__init__.py b/src/centpkg/__init__.py index 3667b98..bd09ce1 100644 --- a/src/centpkg/__init__.py +++ b/src/centpkg/__init__.py @@ -54,7 +54,7 @@ class DistGitDirectory(object): javabranchre = r"openjdk-portable-centos-(?P\d+)" oldbranchre = r"(?P\w+)(?P\d)" rhelmatch = re.search(rhelbranchre, branchtext) - sigmatch = re.match(sigtobranchre, branchtext) + sigmatch = re.search(sigtobranchre, branchtext) distromatch = re.match(distrobranchre, branchtext) javamatch = re.match(javabranchre, branchtext) oldbranchmatch = re.match(oldbranchre, branchtext)