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_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, quarantine: nil, 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, #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_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
#initialize(cask, quarantine: nil, 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.
29 30 31 32 33 34 35 |
# File 'cask/download.rb', line 29 def initialize(cask, quarantine: nil, require_sha: false) super() @cask = cask @quarantine = quarantine @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.
20 21 22 |
# File 'cask/download.rb', line 20 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.
89 90 91 |
# File 'cask/download.rb', line 89 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.
45 46 47 |
# File 'cask/download.rb', line 45 def checksum @checksum ||= cask.sha256 if cask.sha256 != :no_check end |
#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.
227 |
# File 'cask/download.rb', line 227 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.
230 |
# File 'cask/download.rb', line 230 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.
209 210 211 212 213 214 |
# File 'cask/download.rb', line 209 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.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'cask/download.rb', line 105 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 return unless @quarantine return unless Quarantine.available? 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'cask/download.rb', line 63 def fetch(quiet: nil, verify_download_integrity: true, timeout: nil) verify_has_sha if @require_sha 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.
94 95 96 97 98 99 100 101 102 |
# File 'cask/download.rb', line 94 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.
134 135 136 137 138 139 140 141 142 143 |
# File 'cask/download.rb', line 134 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.
156 157 158 159 160 161 162 163 164 165 |
# File 'cask/download.rb', line 156 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? staged_path.parent.rmdir_if_possible staged_path.parent.parent.rmdir_if_possible 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.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'cask/download.rb', line 184 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 ignore_interrupts 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.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'cask/download.rb', line 168 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.
146 147 148 |
# File 'cask/download.rb', line 146 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.
151 152 153 |
# File 'cask/download.rb', line 151 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.
82 83 84 85 86 |
# File 'cask/download.rb', line 82 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.
38 39 40 41 42 |
# File 'cask/download.rb', line 38 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.
217 218 219 220 221 222 223 224 |
# File 'cask/download.rb', line 217 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.
50 51 52 53 54 |
# File 'cask/download.rb', line 50 def version return if cask.version.nil? @version ||= Version.new(cask.version) end |