From 4aae927d527b64a9a2cabf94c9708dcecf21aae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 17 Apr 2024 12:06:26 +0200 Subject: [PATCH] reg: continue downloads was broken after 311492004cec83b6b8040939adee9b20f7499381 --- dcoraid/download/job.py | 10 +++++++++- tests/test_download_job.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dcoraid/download/job.py b/dcoraid/download/job.py index 3a5c9f0..daf8ca3 100644 --- a/dcoraid/download/job.py +++ b/dcoraid/download/job.py @@ -346,7 +346,15 @@ def task_download_resource(self): url = self.get_resource_url() headers = copy.deepcopy(self.api.headers) if self.path_temp.exists(): - # resume previous download + # Resume a previous download. + # We have to update the hash of the current file with + # the data that has already been uploaded. + if (self.sha256sum_dl is None + # We do not verify SHA256 for condensed + and not self.condensed): + with self.path_temp.open("rb") as fd: + while chunk := fd.read(1024**2): + hasher.update(chunk) bytes_present = self.path_temp.stat().st_size headers["Range"] = f"bytes={bytes_present}-" with requests.get(url, diff --git a/tests/test_download_job.py b/tests/test_download_job.py index 7dec22a..2448919 100644 --- a/tests/test_download_job.py +++ b/tests/test_download_job.py @@ -45,6 +45,7 @@ def test_download_resume(): download_path=td) dj2.task_download_resource() dj2.task_verify_resource() + assert not dj2.traceback assert dj2.start_time is not None assert dj2.end_time is not None assert dj2.path.exists()