Class: AbstractFileDownloadStrategy Abstract Private

Inherits:
AbstractDownloadStrategy show all
Defined in:
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.

This class is abstract.

Abstract superclass for all download strategies downloading a single file.

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #url

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#clear_cache, #fetch, #initialize, #ohai, #quiet!, #quiet?, #source_modified_time, #source_revision, #stage, #total_size

Methods included from Utils::Output::Mixin

#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

This class inherits a constructor from AbstractDownloadStrategy

Instance Method Details

#basenamePathname

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.

Returns:



362
363
364
# File 'download_strategy.rb', line 362

def basename
  cached_location.basename.sub(/^[\da-f]{64}--/, "")
end

#cached_locationPathname

Path for storing the completed download.

Returns:



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'download_strategy.rb', line 339

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

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.

Parameters:



367
368
369
370
# File 'download_strategy.rb', line 367

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_sizeInteger?

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.

Returns:



357
358
359
# File 'download_strategy.rb', line 357

def fetched_size
  File.size?(temporary_path) || File.size?(cached_location)
end

Path of the symlink (whose name includes the resource name, version and extension) pointing to #cached_location.

Returns:



327
328
329
330
331
332
333
# File 'download_strategy.rb', line 327

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_pathPathname

Path for storing an incomplete download while the download is still in progress.

Returns:



318
319
320
# File 'download_strategy.rb', line 318

def temporary_path
  @temporary_path ||= T.let(Pathname.new("#{cached_location}.incomplete"), T.nilable(Pathname))
end