Class: VCSDownloadStrategy Abstract Private

Inherits:
AbstractDownloadStrategy show all
Defined in:
download_strategy/vcs_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

Constants inherited from AbstractDownloadStrategy

AbstractDownloadStrategy::HOMEBREW_CONTROLLED_STRATEGIES

Instance Attribute Summary collapse

Attributes inherited from AbstractDownloadStrategy

#cache, #url

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#basename, #chdir, #clear_cache, expand_deferred_environment_for?, #fetched_size, #ohai, #quiet!, #quiet?, #source_modified_time, #source_revision, #stage, #total_size

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #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

#system_command, #system_command!

Methods included from Context

current, current=, #debug?, #deferred_environment_expansion?, #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.

Formula url specs reach download strategies as arbitrary options.

Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'download_strategy/vcs_download_strategy.rb', line 17

def initialize(url, name, version, **meta)
  super
  # Deprecate stable Subversion, CVS, Mercurial and Fossil sources in the next major release.
  # if !head? && !is_a?(GitDownloadStrategy)
  #   odeprecated self.class.to_s, "GitDownloadStrategy or CurlDownloadStrategy", disable: true
  # end
  ref_type = REF_TYPES.find { |type| meta.key?(type) }
  @ref_type = T.let(ref_type, T.nilable(Symbol))
  ref = (meta[ref_type] if ref_type)
  @ref = T.let(ref, T.untyped)
  @revision = T.let(meta[:revision], T.nilable(String))
  cached_location = @cache/Utils.safe_filename("#{name}--#{cache_tag}")
  @cached_location = T.let(cached_location, Pathname)
  @fetching = T.let(false, T::Boolean)
end

Instance Attribute Details

#cached_location ⇒ 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:



11
12
13
# File 'download_strategy/vcs_download_strategy.rb', line 11

def cached_location
  @cached_location
end

Instance Method Details

#command_sandbox ⇒ Sandbox?

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:



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'download_strategy/vcs_download_strategy.rb', line 89

def command_sandbox
  return unless Sandbox.isolate_operation?

  # Reject symlinks before the sandbox resolves its writable paths.
  if cached_location.symlink? || sandbox_write_path.symlink?
    raise "VCS download path is a symlink: #{cached_location}"
  end

  Sandbox.for_operation(write_paths: [sandbox_write_path], network_access: fetching?,
                        home_read_exception: (fetch_home_read_exception if fetching?)).tap do |sandbox|
    allow_fetch_credentials(sandbox) if fetching?
  end
end

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


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

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)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'download_strategy/vcs_download_strategy.rb', line 37

def fetch(timeout: nil)
  @fetching = true
  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
ensure
  @fetching = false
end

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

Returns:



68
69
70
71
# File 'download_strategy/vcs_download_strategy.rb', line 68

def fetch_last_commit
  fetch
  last_commit
end

#fetching? ⇒ 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)


86
# File 'download_strategy/vcs_download_strategy.rb', line 86

def fetching? = @fetching

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


80
81
82
83
# File 'download_strategy/vcs_download_strategy.rb', line 80

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

#last_commit ⇒ String

Return the most recent modified timestamp.

Returns:



110
111
112
# File 'download_strategy/vcs_download_strategy.rb', line 110

def last_commit
  source_modified_time.to_i.to_s
end

#sandbox_write_path ⇒ 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:



104
# File 'download_strategy/vcs_download_strategy.rb', line 104

def sandbox_write_path = cached_location