-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,24 +407,27 @@ def fetch(timeout: nil) | |
|
||
ohai "Downloading #{url}" | ||
|
||
use_cached_location = cached_location.exist? | ||
use_cached_location = false if version.respond_to?(:latest?) && version.latest? | ||
cached_location_valid = cached_location.exist? && !(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)) | ||
EricFromCanada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rescue ErrorDuringExecution | ||
raise unless use_cached_location | ||
raise unless cached_location_valid | ||
end | ||
|
||
# Authorization is no longer valid after redirects | ||
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 | ||
use_cached_location = false | ||
# The cached location is no longer fresh if either: | ||
# - Last-Modified value is newer than the file's timestamp | ||
# - Content-Length value is different than the file's size | ||
cached_location_valid = if cached_location_valid | ||
newer_last_modified = last_modified && last_modified > cached_location.mtime | ||
different_file_size = file_size && file_size != cached_location.size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm tripping over the logic with the naming here. It seems if there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
!(newer_last_modified || different_file_size) | ||
end | ||
|
||
if use_cached_location | ||
if cached_location_valid | ||
puts "Already downloaded: #{cached_location}" | ||
else | ||
begin | ||
|
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.
I know this was pre-existing, but the use of
respond_to?
means this isn't typesafe, do you what the potential types are? (e.g. iflatest?
is only for theCask::DSL::Version
case, than I'd like us to use a static helper method in that class, useto_s
directly, or some other typesafe approach.)🤔 Maybe this will nerd snipe me into typing this file…
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.
'twas my plan all along, bwa ha ha