From 9f9a350e53f56f4a9a3ea2b6c49e2c0367d9155b Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Fri, 10 Jul 2026 00:05:37 +0100 Subject: [PATCH] fix(civitai): restart download when server ignores range request A 200 reply to a resumed download carries the full file, not the remainder; appending it to the partial produced a corrupt file that passed the size check and only failed at hash verification. Truncate the temp file and restart from byte 0 when a Range request comes back as 200 instead of 206. --- modules/civitai/download_civitai.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/civitai/download_civitai.py b/modules/civitai/download_civitai.py index 003467e68..78b9295e8 100644 --- a/modules/civitai/download_civitai.py +++ b/modules/civitai/download_civitai.py @@ -188,6 +188,15 @@ class DownloadManager: log.warning(f'CivitAI download invalid content-type: id={item.id} content-type="{content_type}"') return + # A 200 reply to a Range request means the server ignored the range + # and is sending the whole file; appending it to the partial would + # corrupt it. Truncate and restart from byte 0. + if starting_pos > 0 and r.status_code == 200: + log.warning(f'CivitAI download resume not supported: id={item.id} file="{item.filename}" restarting') + starting_pos = 0 + item.bytes_downloaded = 0 + os.truncate(temp_file, 0) + total_size = int(r.headers.get('content-length', 0)) item.bytes_total = starting_pos + total_size