Skip to content

Commit

Permalink
There would be one case where this wouldn't work
Browse files Browse the repository at this point in the history
When accumulated_size has just been refreshed to zero. Also check
size is greater than zeor to avoid division by zero.

Signed-off-by: Eric Curtin <[email protected]>
  • Loading branch information
ericcurtin committed Feb 8, 2025
1 parent 738eda2 commit 2956111
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ramalama/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def perform_download(self, file, progress):
self.start_time = time.time()
accumulated_size = 0
last_update_time = time.time()
do_final_progress = False
while True:
data = self.response.read(1024)
if not data:
Expand All @@ -66,11 +67,14 @@ def perform_download(self, file, progress):
accumulated_size += size
if time.time() - last_update_time >= 0.1:
self.update_progress(accumulated_size)
do_final_progress = True
accumulated_size = 0
last_update_time = time.time()

if accumulated_size:
self.update_progress(accumulated_size)
if do_final_progress:
if accumulated_size:
self.update_progress(accumulated_size)

print("\033[K", end="\r")

def human_readable_time(self, seconds):
Expand Down

0 comments on commit 2956111

Please sign in to comment.