From 4bd4ab1823a7d4bc218b8057b7f00808fabf7648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 5 Apr 2023 09:34:33 +0200 Subject: [PATCH 3/6] Check remote file with correct hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- pyrpkg/__init__.py | 3 ++- pyrpkg/lookaside.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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) -- 2.39.2