-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
download_strategy: compare cached file size to Content-Length #19460
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some style tweaks and should be good to go.
71f5944
to
14a541f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
# - Content-Length value is different than the file's size | ||
newer_last_modified = last_modified && last_modified > cached_location.mtime | ||
different_file_size = file_size && file_size != cached_location.size | ||
use_cached_location = false if cached_location.exist? && (newer_last_modified || different_file_size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be inscrutable, but if you want to short-circuit:
use_cached_location = false if cached_location.exist? && (newer_last_modified || different_file_size) | |
use_cached_location &&= cached_location.exist? && (newer_last_modified || different_file_size) |
@@ -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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not in this PR, but both the name and return type strongly suggest using a URLMetadata (or such) struct here instead.
Not sure how to get the tests to pass:
|
Ah, I think line 426 needs a |
Odd that |
I'm guessing that there's no |
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Before using a cached download, also check that the Content-Length header returned from the URL matches the size of the file. This should catch instances where a newer version of a cask isn't downloaded because a cask's URL doesn't change between updates, i.e. Homebrew/homebrew-cask#204165.
Fixes Homebrew/homebrew-cask#204166, but there's bound to be edge cases.