Give a resumed download's progress the whole file's size as its total.

The total was "length + have or size or 0", which is the part file's size when a resumed answer names no length:
the bar ran past its end. It is now the expected size, else the server's length plus the part, else unknown.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 22:16:57 -05:00
parent c5aee51601
commit fe041188f5
2 changed files with 42 additions and 1 deletions

View File

@@ -262,7 +262,12 @@ def download(url, dest, sha256=None, size=None, progress=None, cancel=None, head
status = getattr(r, 'status', 200)
if have and status != 206: # the server ignores Range: start over
have = 0
total = int(r.headers.get('Content-Length') or 0) + have or size or 0
# The whole file's size for progress: the expected one, else what the server says is still to come
# plus what the part file holds, else unknown (0: progress then gets the bytes so far as the total).
# "length + have or size or 0" took the part file's size for the whole when a resumed answer named
# no length, and the bar ran past its end.
coming = int(r.headers.get('Content-Length') or 0)
total = size or (coming + have if coming else 0)
with open(part, 'ab' if have else 'wb') as f:
done = have
while True: