Merge pull request #20137 from Homebrew/cached-location-validation

download_strategy: fix caching of `:latest` downloads
This commit is contained in:
Mike McQuaid 2025-06-18 07:33:29 +00:00 committed by GitHub
commit 76470c0d8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -469,8 +469,6 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
ohai "Downloading #{url}" ohai "Downloading #{url}"
cached_location_valid = cached_location.exist? cached_location_valid = cached_location.exist?
v = version
cached_location_valid = false if v.is_a?(Cask::DSL::Version) && v.latest?
resolved_url, _, last_modified, file_size, 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)) resolve_url_basename_time_file_size(url, timeout: Utils::Timer.remaining!(end_time))
@ -484,7 +482,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
# The cached location is no longer fresh if either: # The cached location is no longer fresh if either:
# - Last-Modified value is newer than the file's timestamp # - Last-Modified value is newer than the file's timestamp
# - Content-Length value is different than the file's size # - Content-Length value is different than the file's size
if cached_location_valid && !is_redirection if cached_location_valid
newer_last_modified = last_modified && last_modified > cached_location.mtime newer_last_modified = last_modified && last_modified > cached_location.mtime
different_file_size = file_size&.nonzero? && file_size != cached_location.size different_file_size = file_size&.nonzero? && file_size != cached_location.size
cached_location_valid = !(newer_last_modified || different_file_size) cached_location_valid = !(newer_last_modified || different_file_size)