Class: AbstractDownloadStrategy Abstract Private

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers
Includes:
Context, FileUtils, SystemCommand::Mixin, Utils::Output::Mixin
Defined in:
download_strategy/abstract_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.

Constant Summary collapse

HOMEBREW_CONTROLLED_STRATEGIES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let([
  CurlApacheMirrorDownloadStrategy,
  CurlDownloadStrategy,
  CurlGitHubPackagesDownloadStrategy,
  CurlPostDownloadStrategy,
  HomebrewCurlDownloadStrategy,
  NoUnzipCurlDownloadStrategy,
  PyPIDownloadStrategy,
].freeze, T::Array[T::Class[AbstractDownloadStrategy]])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from SystemCommand::Mixin

#command_sandbox, #system_command, #system_command!

Methods included from Context

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

Constructor Details

#initialize(url, name, version, **meta) ⇒ 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.

Formula url specs reach download strategies as arbitrary options.

Parameters:



38
39
40
41
42
43
44
45
46
47
48
# File 'download_strategy/abstract_download_strategy.rb', line 38

def initialize(url, name, version, **meta)
  @cached_location = T.let(nil, T.nilable(Pathname))
  @ref_type = T.let(nil, T.nilable(Symbol))
  @ref = T.let(nil, T.untyped)
  @url = url
  @name = name
  @version = version
  @cache = T.let(meta.fetch(:cache, HOMEBREW_CACHE), Pathname)
  @meta = meta
  @quiet = T.let(false, T.nilable(T::Boolean))
end

Instance Attribute Details

#cache ⇒ Pathname (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.

Returns:



23
24
25
# File 'download_strategy/abstract_download_strategy.rb', line 23

def cache
  @cache
end

#url ⇒ String (readonly)

The download URL.

Returns:



20
21
22
# File 'download_strategy/abstract_download_strategy.rb', line 20

def url
  @url
end

Class Method Details

.expand_deferred_environment_for?(downloader) ⇒ 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.

Parameters:

Returns:

  • (Boolean)


84
85
86
# File 'download_strategy/abstract_download_strategy.rb', line 84

def self.expand_deferred_environment_for?(downloader)
  HOMEBREW_CONTROLLED_STRATEGIES.include?(downloader.class)
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.

Returns:



149
150
151
# File 'download_strategy/abstract_download_strategy.rb', line 149

def basename
  cached_location.basename
end

#cached_location ⇒ Pathname

This method is abstract.

Location of the cached download.

Returns:



68
# File 'download_strategy/abstract_download_strategy.rb', line 68

def cached_location; end

#chdir(&block) ⇒ 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.

Parameters:

  • block (T.proc.void)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'download_strategy/abstract_download_strategy.rb', line 109

def chdir(&block)
  entries = Dir["*"]
  raise "Empty archive" if entries.empty?

  if entries.length != 1
    yield
    return
  end

  if File.directory? entries.fetch(0)
    Dir.chdir(entries.fetch(0)) { |_dir| yield }
  else
    yield
  end
end

#clear_cache ⇒ void

This method returns an undefined value.

Remove #cached_location and any other files associated with the resource from the cache.



144
145
146
# File 'download_strategy/abstract_download_strategy.rb', line 144

def clear_cache
  rm_rf(cached_location)
end

#fetch(timeout: nil) ⇒ void

This method returns an undefined value.

Download and cache the resource at #cached_location.

Parameters:

  • timeout (Float, Integer, nil) (defaults to: nil)


54
# File 'download_strategy/abstract_download_strategy.rb', line 54

def fetch(timeout: nil); 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.

Total bytes downloaded if available.

Returns:



58
# File 'download_strategy/abstract_download_strategy.rb', line 58

def fetched_size; end

#ohai(title, *sput) ⇒ 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.

Parameters:

  • title (String, Exception)
  • sput (T.anything)


154
155
156
# File 'download_strategy/abstract_download_strategy.rb', line 154

def ohai(title, *sput)
  super unless quiet?
end

#quiet! ⇒ void

This method returns an undefined value.

Disable any output during downloading.



74
75
76
# File 'download_strategy/abstract_download_strategy.rb', line 74

def quiet!
  @quiet = T.let(true, T.nilable(T::Boolean))
end

#quiet? ⇒ 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.

Returns:

  • (Boolean)


79
80
81
# File 'download_strategy/abstract_download_strategy.rb', line 79

def quiet?
  Context.current.quiet? || @quiet || false
end

#source_modified_time ⇒ Time

Returns the most recent modified time for all files in the current working directory after stage.

Returns:



129
130
131
# File 'download_strategy/abstract_download_strategy.rb', line 129

def source_modified_time
  Pathname.pwd.to_enum(:find).select(&:file?).map(&:mtime).max
end

#source_revision ⇒ String?

Return the checked out source revision for version control downloads.

Returns:



137
# File 'download_strategy/abstract_download_strategy.rb', line 137

def source_revision; end

#stage(&block) ⇒ void

This method returns an undefined value.

Unpack #cached_location into the current working directory.

Additionally, if a block is given, the working directory was previously empty and a single directory is extracted from the archive, the block will be called with the working directory changed to that directory. Otherwise this method will return, or the block will be called, without changing the current working directory.

Parameters:

  • block (T.proc.void, nil)


98
99
100
101
102
103
104
105
106
# File 'download_strategy/abstract_download_strategy.rb', line 98

def stage(&block)
  UnpackStrategy.detect(cached_location,
                        prioritize_extension: true,
                        ref_type: @ref_type, ref: @ref)
                .extract_nestedly(basename:,
                                  prioritize_extension: true,
                                  verbose:              verbose? && !quiet?)
  chdir(&block) if block
end

#total_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.

Total download size if available.

Returns:



62
# File 'download_strategy/abstract_download_strategy.rb', line 62

def total_size; end