Class: AbstractFileDownloadStrategy Abstract Private
- Inherits:
-
AbstractDownloadStrategy
- Object
- AbstractDownloadStrategy
- AbstractFileDownloadStrategy
- Defined in:
- download_strategy/abstract_file_download_strategy.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Abstract superclass for all download strategies downloading a single file.
Direct Known Subclasses
CurlDownloadStrategy, GitHubArtifactDownloadStrategy, LocalBottleDownloadStrategy
Constant Summary
Constants inherited from AbstractDownloadStrategy
AbstractDownloadStrategy::HOMEBREW_CONTROLLED_STRATEGIES
Instance Attribute Summary
Attributes inherited from AbstractDownloadStrategy
Instance Method Summary collapse
- #basename ⇒ Pathname private
-
#cached_location ⇒ Pathname
Path for storing the completed download.
- #create_symlink_to_cached_download(target_cached_location) ⇒ void private
- #fetched_size ⇒ Integer? private
- #parse_basename(url, search_query: true) ⇒ String private
-
#symlink_location ⇒ Pathname
Path of the symlink (whose name includes the resource name, version and extension) pointing to #cached_location.
-
#temporary_path ⇒ Pathname
Path for storing an incomplete download while the download is still in progress.
Methods inherited from AbstractDownloadStrategy
#clear_cache, expand_deferred_environment_for?, #fetch, #initialize, #ohai, #quiet!, #quiet?, #source_modified_time, #source_revision, #stage, #total_size
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Methods included from SystemCommand::Mixin
#system_command, #system_command!
Methods included from Context
current, current=, #debug?, #deferred_environment_expansion?, #quiet?, #verbose?, #with_context
Constructor Details
This class inherits a constructor from AbstractDownloadStrategy
Instance Method Details
#basename ⇒ Pathname
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
56 57 58 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 56 def basename cached_location.basename.sub(/^[\da-f]{64}--/, "") end |
#cached_location ⇒ Pathname
Path for storing the completed download.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 33 def cached_location return @cached_location if @cached_location url_sha256 = Digest::SHA256.hexdigest(url) downloads = Pathname.glob(HOMEBREW_CACHE/"downloads/#{url_sha256}--*") .reject { |path| path.extname.end_with?(".incomplete") } @cached_location = T.let( if downloads.one? downloads.fetch(0) else HOMEBREW_CACHE/"downloads/#{url_sha256}--#{Utils.safe_filename(resolved_basename)}" end, T.nilable(Pathname) ) T.must(@cached_location) end |
#create_symlink_to_cached_download(target_cached_location) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
61 62 63 64 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 61 def create_symlink_to_cached_download(target_cached_location) symlink_location.dirname.mkpath FileUtils.ln_s target_cached_location.relative_path_from(symlink_location.dirname), symlink_location, force: true end |
#fetched_size ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
51 52 53 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 51 def fetched_size File.size?(temporary_path) || File.size?(cached_location) end |
#parse_basename(url, search_query: true) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 67 def parse_basename(url, search_query: true) components = { path: T.let([], T::Array[String]), query: T.let([], T::Array[String]) } file_url = T.let(false, T::Boolean) if url.match?(URI::RFC2396_PARSER.make_regexp) uri = URI(url) file_url = uri.scheme == "file" if (uri_query = uri.query.presence) URI.decode_www_form(uri_query).each do |key, param| components[:query] << param if search_query next if key != "response-content-disposition" query_basename = param[/attachment;\s*filename=(["']?)(.+)\1/i, 2] return File.basename(query_basename) if query_basename end end if (uri_path = uri.path.presence) components[:path] = uri_path.split("/").filter_map do |part| URI::RFC2396_PARSER.unescape(part).presence end end else components[:path] = [url] end # We need a Pathname because we've monkeypatched extname to support double # extensions (e.g. tar.gz). # Given a URL like https://example.com/download.php?file=foo-1.0.tar.gz # the basename we want is "foo-1.0.tar.gz", not "download.php". # Skipped for file:// URLs since their paths can contain ancestor # directories with dots (e.g. "github.com") that aren't real extensions. unless file_url [*components[:path], *components[:query]].reverse_each do |path| path = Pathname(path) return path.basename.to_s if path.extname.present? end end filename = components[:path].last return "" if filename.blank? File.basename(filename) end |
#symlink_location ⇒ Pathname
Path of the symlink (whose name includes the resource name, version and extension) pointing to #cached_location.
21 22 23 24 25 26 27 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 21 def symlink_location return T.must(@symlink_location) if defined?(@symlink_location) ext = Pathname(parse_basename(url)).extname @symlink_location = T.let(@cache/Utils.safe_filename("#{name}--#{version}#{ext}"), T.nilable(Pathname)) T.must(@symlink_location) end |
#temporary_path ⇒ Pathname
Path for storing an incomplete download while the download is still in progress.
12 13 14 |
# File 'download_strategy/abstract_file_download_strategy.rb', line 12 def temporary_path @temporary_path ||= T.let(Pathname.new("#{cached_location}.incomplete"), T.nilable(Pathname)) end |