From 4bd4ab1823a7d4bc218b8057b7f00808fabf7648 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Apr 12 2023 00:02:36 +0000 Subject: Check remote file with correct hash The configured hashtype doesn't have to actually be used. There can be old repos that still use md5. JIRA: RHELCMP-11508 Signed-off-by: Lubomír Sedlář --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index d3a7a1c..0b9a869 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -4548,7 +4548,8 @@ class Commands(object): file_exists_in_lookaside = self.lookasidecache.remote_file_exists_head( self.ns_repo_name if self.lookaside_namespaced else self.repo_name, filename, - hash) + hash, + hashtype=entry.hashtype) if not file_exists_in_lookaside: self.log.error('Source file (or tarball) \'{}\' wasn\'t uploaded to the lookaside ' 'cache. Push operation was cancelled.'.format(filename)) diff --git a/pyrpkg/lookaside.py b/pyrpkg/lookaside.py index ecbf12b..3efcd88 100644 --- a/pyrpkg/lookaside.py +++ b/pyrpkg/lookaside.py @@ -200,7 +200,7 @@ class CGILookasideCache(object): if not self.file_is_valid(outfile, hash, hashtype=hashtype): raise DownloadError('%s failed checksum' % filename) - def remote_file_exists_head(self, name, filename, hash): + def remote_file_exists_head(self, name, filename, hash, hashtype): """Verify whether a file exists on the lookaside cache. Uses a HTTP HEAD request and doesn't require authentication. @@ -209,10 +209,11 @@ class CGILookasideCache(object): the server side expects). :param str filename: The name of the file to check for. :param str hash: The known good hash of the file. + :param str hashtype: The type of hash """ urled_file = urllib.parse.quote(filename) - url = self.get_download_url(name, urled_file, hash, self.hashtype) + url = self.get_download_url(name, urled_file, hash, hashtype or self.hashtype) c = pycurl.Curl() c.setopt(pycurl.URL, url)