Class: Cask::Download Private
- Includes:
- Context, Downloadable
- Defined in:
- cask/download.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.
A download corresponding to a Cask.
Instance Attribute Summary collapse
- #cask ⇒ ::Cask::Cask readonly private
Attributes included from Downloadable
Instance Method Summary collapse
- #basename ⇒ Pathname private
- #checksum ⇒ ::Checksum? private
- #download_name ⇒ String private
- #download_queue_name ⇒ String private
- #download_queue_type ⇒ String private
- #downloaded_and_valid? ⇒ Boolean private
- #extract_primary_container(to:, verbose:, container: nil) ⇒ void private
- #fetch(quiet: nil, verify_download_integrity: true, timeout: nil) ⇒ Pathname private
- #initialize(cask, require_sha: false) ⇒ void constructor private
- #primary_container ⇒ UnpackStrategy private
- #process_rename_operations(target_dir:) ⇒ void private
- #purge_staged_from_download_queue(command: SystemCommand) ⇒ void private
- #stage_from_download_queue(download, pour:) ⇒ void private
- #stage_from_download_queue?(download, pour:) ⇒ Boolean private
- #staged_path_from_download_queue ⇒ Pathname private
- #staged_path_from_download_queue_marker ⇒ Pathname private
- #time_file_size(timeout: nil) ⇒ Array<([Time, nil], Integer)> private
- #url ⇒ ::URL? private
- #verify_download_integrity(filename) ⇒ void private
- #version ⇒ Version? private
Methods included from Context
current, current=, #debug?, #deferred_environment_expansion?, #quiet?, #verbose?, #with_context
Methods included from Downloadable
#cached_download, #clear_cache, #download_queue_message, #download_strategy, #downloaded!, #downloaded?, #downloader, #downloading!, #extracting!, #fetched_size, #freeze, #initialize_dup, #total_size, verification_cache, #verified!, #verifying!
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_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(cask, require_sha: false) ⇒ 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.
31 32 33 34 35 36 |
# File 'cask/download.rb', line 31 def initialize(cask, require_sha: false) super() @cask = cask @require_sha = require_sha end |
Instance Attribute Details
#cask ⇒ ::Cask::Cask (readonly)
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.
23 24 25 |
# File 'cask/download.rb', line 23 def cask @cask end |
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.
91 92 93 |
# File 'cask/download.rb', line 91 def basename downloader.basename end |
#checksum ⇒ ::Checksum?
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.
46 47 48 |
# File 'cask/download.rb', line 46 def checksum @checksum ||= cask.sha256 if cask.sha256 != :no_check end |
#download_name ⇒ 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.
232 |
# File 'cask/download.rb', line 232 def download_name = cask.token |
#download_queue_name ⇒ 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.
226 |
# File 'cask/download.rb', line 226 def download_queue_name = "#{cask.token} (#{version})" |
#download_queue_type ⇒ 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.
229 |
# File 'cask/download.rb', line 229 def download_queue_type = "Cask" |
#downloaded_and_valid? ⇒ Boolean
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.
208 209 210 211 212 213 |
# File 'cask/download.rb', line 208 def downloaded_and_valid? return false unless super quarantine(cached_download) true end |
#extract_primary_container(to:, verbose:, container: nil) ⇒ 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.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'cask/download.rb', line 107 def extract_primary_container(to:, verbose:, container: nil) odebug "Extracting primary container" container ||= primary_container raise "unexpected nil primary_container" unless container odebug "Using container class #{container.class} for #{container.path}" if (nested_container = cask.container&.nested) Dir.mktmpdir("cask-installer", HOMEBREW_TEMP) do |tmpdir| tmpdir = Pathname(tmpdir) container.extract(to: tmpdir, basename:, verbose:) FileUtils.chmod_R "+rw", tmpdir/nested_container, force: true, verbose: verbose UnpackStrategy.detect(tmpdir/nested_container, merge_xattrs: true) .extract_nestedly(to:, verbose:) end else container.extract_nestedly(to:, basename:, verbose:) end Quarantine.propagate(from: container.path, to:) end |
#fetch(quiet: nil, verify_download_integrity: true, timeout: nil) ⇒ 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.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'cask/download.rb', line 64 def fetch(quiet: nil, verify_download_integrity: true, timeout: nil) verify_has_sha if @require_sha || (@cask.sha256.nil? && (@cask.on_system_blocks_exist? || @cask.loaded_from_api?)) downloader.quiet! if quiet begin super(verify_download_integrity: false, timeout:) rescue DownloadError => e error = CaskError.new("Download failed on Cask '#{cask}' with message: #{e.cause}") error.set_backtrace e.backtrace raise error end downloaded_path = cached_download quarantine(downloaded_path) self.verify_download_integrity(downloaded_path) if verify_download_integrity downloaded_path end |
#primary_container ⇒ UnpackStrategy
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.
96 97 98 99 100 101 102 103 104 |
# File 'cask/download.rb', line 96 def primary_container @primary_container ||= T.let( begin downloaded_path = cask.download || fetch(quiet: true) UnpackStrategy.detect(downloaded_path, type: cask.container&.type, merge_xattrs: true) end, T.nilable(UnpackStrategy), ) end |
#process_rename_operations(target_dir:) ⇒ 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.
133 134 135 136 137 138 139 140 141 142 |
# File 'cask/download.rb', line 133 def process_rename_operations(target_dir:) return if cask.rename.empty? odebug "Processing rename operations in #{target_dir}" cask.rename.each do |rename_operation| odebug "Renaming #{rename_operation.from} to #{rename_operation.to}" rename_operation.perform_rename(target_dir) end end |
#purge_staged_from_download_queue(command: SystemCommand) ⇒ 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.
155 156 157 158 159 160 161 162 163 164 |
# File 'cask/download.rb', line 155 def purge_staged_from_download_queue(command: SystemCommand) staged_marker = staged_path_from_download_queue_marker Utils.(staged_marker, command:) if staged_marker.symlink? || staged_marker.exist? staged_path = staged_path_from_download_queue Utils.(staged_path, command:) if staged_path.exist? ::Utils::Path.rmdir_if_possible(staged_path.parent) ::Utils::Path.rmdir_if_possible(staged_path.parent.parent) end |
#stage_from_download_queue(download, pour:) ⇒ 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.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'cask/download.rb', line 183 def stage_from_download_queue(download, pour:) return unless stage_from_download_queue?(download, pour:) purge_staged_from_download_queue cask.download ||= download extract_primary_container( to: staged_path_from_download_queue, verbose: false, container: UnpackStrategy.detect( download, type: cask.container&.type, merge_xattrs: true, ), ) process_rename_operations(target_dir: staged_path_from_download_queue) FileUtils.ln_s(staged_path_from_download_queue, staged_path_from_download_queue_marker) # Catch any exception type here to clean up partial queued extractions. rescue Exception # rubocop:disable Lint/RescueException ::Utils::Interrupts.ignore do purge_staged_from_download_queue end raise end |
#stage_from_download_queue?(download, pour:) ⇒ Boolean
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.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'cask/download.rb', line 167 def stage_from_download_queue?(download, pour:) return false unless pour return false if cask.staged_path.exist? || staged_path_from_download_queue_marker.exist? UnpackStrategy.detect(download, type: cask.container&.type, merge_xattrs: true).dependencies.all? do |dependency| case dependency when Formula dependency.any_version_installed? && dependency.optlinked? when Cask dependency.installed? end end end |
#staged_path_from_download_queue ⇒ 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.
145 146 147 |
# File 'cask/download.rb', line 145 def staged_path_from_download_queue HOMEBREW_PREFIX/"var/homebrew/tmp/.caskroom"/cask.staged_path.relative_path_from(Caskroom.path) end |
#staged_path_from_download_queue_marker ⇒ 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.
150 151 152 |
# File 'cask/download.rb', line 150 def staged_path_from_download_queue_marker Pathname("#{staged_path_from_download_queue}.staged") end |
#time_file_size(timeout: nil) ⇒ Array<([Time, nil], 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.
84 85 86 87 88 |
# File 'cask/download.rb', line 84 def time_file_size(timeout: nil) raise ArgumentError, "not supported for this download strategy" unless downloader.is_a?(CurlDownloadStrategy) T.cast(downloader, CurlDownloadStrategy).resolved_time_file_size(timeout:) end |
#url ⇒ ::URL?
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.
39 40 41 42 43 |
# File 'cask/download.rb', line 39 def url return if (cask_url = cask.url).nil? @url ||= ::URL.new(cask_url.to_s, cask_url.specs) end |
#verify_download_integrity(filename) ⇒ 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.
216 217 218 219 220 221 222 223 |
# File 'cask/download.rb', line 216 def verify_download_integrity(filename) if no_checksum_defined? && !official_cask_tap? opoo "No checksum defined for cask '#{@cask}', skipping verification." return end super end |
#version ⇒ Version?
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 54 55 |
# File 'cask/download.rb', line 51 def version return if cask.version.nil? @version ||= Version.new(cask.version) end |