test: Detect truncated download in get_previous_releases.py
This commit is contained in:
1 file changed
+4
-1
@@ -122,7 +122,7 @@ def download_from_url(url, archive):
|
|||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
raise RuntimeError(f"HTTP request failed with status code: {response.status}")
|
raise RuntimeError(f"HTTP request failed with status code: {response.status}")
|
||||||
|
|
||||||
total_size = int(response.getheader('Content-Length', 0))
|
total_size = int(response.getheader("Content-Length"))
|
||||||
progress_bytes = 0
|
progress_bytes = 0
|
||||||
|
|
||||||
with open(archive, 'wb') as file:
|
with open(archive, 'wb') as file:
|
||||||
@@ -134,6 +134,9 @@ def download_from_url(url, archive):
|
|||||||
progress_bytes += len(chunk)
|
progress_bytes += len(chunk)
|
||||||
progress_hook(progress_bytes, total_size)
|
progress_hook(progress_bytes, total_size)
|
||||||
|
|
||||||
|
if progress_bytes < total_size:
|
||||||
|
raise RuntimeError(f"Download incomplete: expected {total_size} bytes, got {progress_bytes} bytes")
|
||||||
|
|
||||||
print('\n', flush=True, end="") # Flush to avoid error output on the same line.
|
print('\n', flush=True, end="") # Flush to avoid error output on the same line.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user