Module: Homebrew::Reinstall Private

Defined in:
reinstall.rb

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

Class Method Summary collapse

Class Method Details

.reinstall_formula(formula, flags:, force_bottle: false, build_from_source_formulae: [], interactive: false, keep_tmp: false, debug_symbols: false, force: false, debug: false, quiet: false, verbose: false, git: false) ⇒ Object

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.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'reinstall.rb', line 10

def self.reinstall_formula(
  formula,
  flags:,
  force_bottle: false,
  build_from_source_formulae: [],
  interactive: false,
  keep_tmp: false,
  debug_symbols: false,
  force: false,
  debug: false,
  quiet: false,
  verbose: false,
  git: false
)
  if formula.opt_prefix.directory?
    keg = Keg.new(formula.opt_prefix.resolved_path)
    tab = keg.tab
    link_keg = keg.linked?
    installed_as_dependency = tab.installed_as_dependency
    installed_on_request = tab.installed_on_request
    build_bottle = tab.built_bottle?
    backup keg
  else
    link_keg = nil
    installed_as_dependency = false
    installed_on_request = true
    build_bottle = false
  end

  build_options = BuildOptions.new(Options.create(flags), formula.options)
  options = build_options.used_options
  options |= formula.build.used_options
  options &= formula.options

  fi = FormulaInstaller.new(
    formula,
    **{
      options:,
      link_keg:,
      installed_as_dependency:,
      installed_on_request:,
      build_bottle:,
      force_bottle:,
      build_from_source_formulae:,
      git:,
      interactive:,
      keep_tmp:,
      debug_symbols:,
      force:,
      debug:,
      quiet:,
      verbose:,
    }.compact,
  )
  fi.prelude
  fi.fetch

  oh1 "Reinstalling #{Formatter.identifier(formula.full_name)} #{options.to_a.join " "}"

  fi.install
  fi.finish
rescue FormulaInstallationAlreadyAttemptedError
  nil
rescue Exception # rubocop:disable Lint/RescueException
  ignore_interrupts { restore_backup(keg, link_keg, verbose:) }
  raise
else
  begin
    FileUtils.rm_r(backup_path(keg)) if backup_path(keg).exist?
  rescue Errno::EACCES, Errno::ENOTEMPTY
    odie <<~EOS
      Could not remove #{backup_path(keg).parent.basename} backup keg! Do so manually:
        sudo rm -rf #{backup_path(keg)}
    EOS
  end
end