blob: f5d6437bd9531f49e59b1badd1ead3a2fe20ba4a (
plain)
| 1
2
3
4
5
6
7
8
9
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
 | #:  * `reinstall` <formula>:
#:    Uninstall and then install <formula>.
require "formula_installer"
require "development_tools"
module Homebrew
  module_function
  def reinstall
    FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
    ARGV.resolved_formulae.each do |f|
      if f.pinned?
        onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
        next
      end
      Migrator.migrate_if_needed(f)
      reinstall_formula(f)
    end
  end
  def reinstall_formula(f)
    if f.opt_prefix.directory?
      keg = Keg.new(f.opt_prefix.resolved_path)
      backup keg
    end
    build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options)
    options = build_options.used_options
    options |= f.build.used_options
    options &= f.options
    fi = FormulaInstaller.new(f)
    fi.options              = options
    fi.invalid_option_names = build_options.invalid_option_names
    fi.build_bottle         = ARGV.build_bottle? || (!f.bottled? && f.build.bottle?)
    fi.build_from_source    = ARGV.build_from_source? || ARGV.build_all_from_source?
    fi.force_bottle         = ARGV.force_bottle?
    fi.interactive          = ARGV.interactive?
    fi.git                  = ARGV.git?
    fi.verbose              = ARGV.verbose?
    fi.debug                = ARGV.debug?
    fi.prelude
    oh1 "Reinstalling #{f.full_name} #{options.to_a.join " "}"
    fi.install
    fi.finish
  rescue FormulaInstallationAlreadyAttemptedError
    # next
  rescue Exception
    ignore_interrupts { restore_backup(keg, f) }
    raise
  else
    backup_path(keg).rmtree if backup_path(keg).exist?
  end
  def backup(keg)
    keg.unlink
    keg.rename backup_path(keg)
  end
  def restore_backup(keg, formula)
    path = backup_path(keg)
    return unless path.directory?
    Pathname.new(keg).rmtree if keg.exist?
    path.rename keg
    keg.link unless formula.keg_only?
  end
  def backup_path(path)
    Pathname.new "#{path}.reinstall"
  end
end
 |