Class: VCSDownloadStrategy 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 from a version control system.

Constant Summary collapse

REF_TYPES =

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.

[:tag, :branch, :revisions, :revision].freeze

Instance Attribute Summary collapse

Attributes inherited from AbstractDownloadStrategy

#cache, #url

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#basename, #clear_cache, #fetched_size, #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

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

Parameters:



220
221
222
223
224
225
226
227
# File 'download_strategy.rb', line 220

def initialize(url, name, version, **meta)
  super
  extracted_ref = extract_ref(meta)
  @ref_type = T.let(extracted_ref.fetch(0), T.nilable(Symbol))
  @ref = T.let(extracted_ref.fetch(1), T.untyped)
  @revision = T.let(meta[:revision], T.nilable(String))
  @cached_location = T.let(@cache/Utils.safe_filename("#{name}--#{cache_tag}"), Pathname)
end

Instance Attribute Details

#cached_locationPathname (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:



215
216
217
# File 'download_strategy.rb', line 215

def cached_location
  @cached_location
end

Instance Method Details

#commit_outdated?(commit) ⇒ 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)


267
268
269
270
# File 'download_strategy.rb', line 267

def commit_outdated?(commit)
  @last_commit ||= T.let(fetch_last_commit, T.nilable(String))
  commit != @last_commit
end

#fetch(timeout: nil) ⇒ void

This method returns an undefined value.

Download and cache the repository at #cached_location.

Parameters:

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


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'download_strategy.rb', line 233

def fetch(timeout: nil)
  end_time = Time.now + timeout if timeout

  ohai "Cloning #{url}"

  if cached_location.exist? && repo_valid?
    puts "Updating #{cached_location}"
    update(timeout: end_time)
  elsif cached_location.exist?
    puts "Removing invalid repository from cache"
    clear_cache
    clone_repo(timeout: end_time)
  else
    clone_repo(timeout: end_time)
  end

  v = version
  v.update_commit(last_commit) if v.is_a?(Version) && head?

  return if @ref_type != :tag || @revision.blank? || current_revision.blank? || current_revision == @revision

  raise <<~EOS
    #{@ref} tag should be #{@revision}
    but is actually #{current_revision}
  EOS
end

#fetch_last_commitString

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:



261
262
263
264
# File 'download_strategy.rb', line 261

def fetch_last_commit
  fetch
  last_commit
end

#head?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)


273
274
275
276
# File 'download_strategy.rb', line 273

def head?
  v = version
  v.is_a?(Version) ? v.head? : false
end

#last_commitString

Return the most recent modified timestamp.

Returns:



282
283
284
# File 'download_strategy.rb', line 282

def last_commit
  source_modified_time.to_i.to_s
end