Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Library/Homebrew/download_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,21 @@ def message_with_progress(downloadable, future, message)

max_phase_length = 11
phase = format("%-<phase>#{max_phase_length}s", phase: downloadable.phase.to_s.capitalize)
progress = " [#{phase} #{formatted_fetched_size}/#{formatted_total_size}]"
progress_bar = if future.fulfilled?
""
else
percent = if (total_size = downloadable.total_size)
fetched_size.to_f / [1, total_size].max
else
0.0
end
bar_length = [4, available_width / 5].max
bar_used = (percent * bar_length).round
Comment on lines +300 to +306
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When total_size is 0 or very small, the percentage calculation can exceed 1.0, causing bar_used to be larger than bar_length. This would result in a negative count for bar_pending on line 308, causing an ArgumentError when attempting to multiply a string by a negative number.

Consider clamping the percent value:

percent = if (total_size = downloadable.total_size)
  (fetched_size.to_f / [1, total_size].max).clamp(0.0, 1.0)
else
  0.0
end

Copilot uses AI. Check for mistakes.
bar_completed = "━" * bar_used
bar_pending = "┈" * (bar_length - bar_used)
"#{bar_completed}#{bar_pending} "
end
progress = " #{progress_bar}#{phase} #{formatted_fetched_size}/#{formatted_total_size}"
message_length = available_width - progress.length
return message[0, available_width].to_s unless message_length.positive?

Expand Down
Loading