Class: LocalPatch Private

Inherits:
EmbeddedPatch show all
Defined in:
local_patch.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 patch file stored locally within a formula repository.

Instance Attribute Summary collapse

Attributes inherited from EmbeddedPatch

#strip

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EmbeddedPatch

#apply, #external?

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, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #pretty_upgradable

Constructor Details

#initialize(strip, file) ⇒ 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:



25
26
27
28
# File 'local_patch.rb', line 25

def initialize(strip, file)
  super(strip)
  @file = file
end

Instance Attribute Details

#fileString, 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:



9
10
11
# File 'local_patch.rb', line 9

def file
  @file
end

#ownerResource::Owner? (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:



12
13
14
# File 'local_patch.rb', line 12

def owner
  @owner
end

Class Method Details

.valid_path?(path_string) ⇒ 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)


15
16
17
18
19
20
21
22
# File 'local_patch.rb', line 15

def self.valid_path?(path_string)
  path = Pathname(path_string).cleanpath
  path_string.present? &&
    !path_string.end_with?("/") &&
    !path.absolute? &&
    %w[. ..].exclude?(path.to_s) &&
    !path.to_s.start_with?("../")
end

Instance Method Details

#contentsString

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:

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'local_patch.rb', line 31

def contents
  owner = self.owner
  raise ArgumentError, "LocalPatch#contents called before owner was set!" unless owner

  formula = T.cast(owner, SoftwareSpec).owner
  raise ArgumentError, "LocalPatch#contents requires a formula owner!" unless formula.is_a?(::Formula)

  repository_path = repository_path(formula)
  file_path = repository_path/Pathname(file)
  repository_realpath = repository_path.realpath
  file_realpath = begin
    file_path.realpath
  rescue Errno::ENOENT
    raise ArgumentError, "Patch file does not exist: #{file}"
  end
  if file_realpath.ascend.none?(repository_realpath)
    raise ArgumentError, "Patch file must be within the formula repository."
  end
  raise ArgumentError, "Patch file must be a file: #{file}" unless file_realpath.file?

  file_realpath.read
end