Skip to content

Commit

Permalink
download_strategy: compare cached size to Content-Length
Browse files Browse the repository at this point in the history
  • Loading branch information
EricFromCanada committed Mar 10, 2025
1 parent e8419bc commit 71f5944
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def fetch(timeout: nil)
use_cached_location = cached_location.exist?
use_cached_location = false if version.respond_to?(:latest?) && version.latest?

resolved_url, _, last_modified, _, is_redirection = begin
resolved_url, _, last_modified, file_size, is_redirection = begin
resolve_url_basename_time_file_size(url, timeout: Utils::Timer.remaining!(end_time))
rescue ErrorDuringExecution
raise unless use_cached_location
Expand All @@ -420,7 +420,9 @@ def fetch(timeout: nil)
meta[:headers]&.delete_if { |header| header.start_with?("Authorization") } if is_redirection

# The cached location is no longer fresh if Last-Modified is after the file's timestamp
if cached_location.exist? && last_modified && last_modified > cached_location.mtime
if cached_location.exist? && (
(last_modified && last_modified > cached_location.mtime) || (file_size && file_size != cached_location.size)
)
use_cached_location = false
end

Expand Down

0 comments on commit 71f5944

Please sign in to comment.