From 05cf792b2631c1da46a73f24d766782bee04672f Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Wed, 2 Nov 2022 13:35:45 +0100 Subject: [PATCH] Add the file_md5 to the download function so it can cache and verify --- lib/db_revision.py | 3 +-- lib/git_exporter.py | 4 +++- lib/obs.py | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/db_revision.py b/lib/db_revision.py index 4458fe7..cf2e4aa 100644 --- a/lib/db_revision.py +++ b/lib/db_revision.py @@ -216,8 +216,7 @@ class DBRevision: to_delete = [] if current_rev: old_files = { - e["name"]: f"{entry['md5']}-{entry['size']}" - for e in current_rev.files_list(db) + e["name"]: f"{e['md5']}-{e['size']}" for e in current_rev.files_list(db) } else: old_files = dict() diff --git a/lib/git_exporter.py b/lib/git_exporter.py index 5d40182..f988205 100644 --- a/lib/git_exporter.py +++ b/lib/git_exporter.py @@ -66,6 +66,7 @@ class GitExporter: name, revision.srcmd5, self.git.path, + file_md5=file_md5, ) # Validate the MD5 of the downloaded file if md5(self.git.path / name) != file_md5: @@ -137,7 +138,7 @@ class GitExporter: if not self.limit_download(file): continue self.git.remove(file) - for file in to_download: + for file, md5 in to_download: if not self.limit_download(file): continue self.obs.download( @@ -146,6 +147,7 @@ class GitExporter: file, flat.commit.expanded_srcmd5, self.git.path, + file_md5=md5, ) self.git.add(file) diff --git a/lib/obs.py b/lib/obs.py index 217e915..05af330 100644 --- a/lib/obs.py +++ b/lib/obs.py @@ -152,7 +152,13 @@ class OBS: return osc.core.http_GET(url) def download( - self, project: str, package: str, name: str, revision: str, dirpath: str + self, + project: str, + package: str, + name: str, + revision: str, + dirpath: str, + file_md5: str, ) -> None: with (dirpath / name).open("wb") as f: f.write(self._download(project, package, name, revision).read())