Module: Homebrew::Uninstall Private

Defined in:
uninstall.rb

Overview

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.

Helper module for uninstalling kegs.

Defined Under Namespace

Classes: DependentsMessage, DeveloperDependentsMessage, NondeveloperDependentsMessage

Class Method Summary collapse

Class Method Details

.check_for_dependents(kegs, casks: [], named_args: []) ⇒ 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.



106
107
108
109
110
111
112
113
114
115
116
# File 'uninstall.rb', line 106

def self.check_for_dependents(kegs, casks: [], named_args: [])
  return false unless (result = InstalledDependents.find_some_installed_dependents(kegs, casks:))

  if Homebrew::EnvConfig.developer?
    DeveloperDependentsMessage.new(*result, named_args:).output
  else
    NondeveloperDependentsMessage.new(*result, named_args:).output
  end

  true
end

.handle_unsatisfied_dependents(kegs_by_rack, casks: [], ignore_dependencies: false, named_args: []) ⇒ 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.



96
97
98
99
100
101
102
103
104
# File 'uninstall.rb', line 96

def self.handle_unsatisfied_dependents(kegs_by_rack, casks: [], ignore_dependencies: false, named_args: [])
  return if ignore_dependencies

  all_kegs = kegs_by_rack.values.flatten(1)
  check_for_dependents(all_kegs, casks:, named_args:)
rescue MethodDeprecatedError
  # Silently ignore deprecations when uninstalling.
  nil
end

.rm_pin(rack) ⇒ 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.



160
161
162
163
164
# File 'uninstall.rb', line 160

def self.rm_pin(rack)
  Formulary.from_rack(rack).unpin
rescue
  nil
end

.uninstall_kegs(kegs_by_rack, casks: [], force: false, ignore_dependencies: false, named_args: []) ⇒ 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.



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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'uninstall.rb', line 9

def self.uninstall_kegs(kegs_by_rack, casks: [], force: false, ignore_dependencies: false, named_args: [])
  handle_unsatisfied_dependents(kegs_by_rack,
                                casks:,
                                ignore_dependencies:,
                                named_args:)
  return if Homebrew.failed?

  kegs_by_rack.each do |rack, kegs|
    if force
      name = rack.basename

      if rack.directory?
        puts "Uninstalling #{name}... (#{rack.abv})"
        kegs.each do |keg|
          keg.unlink
          keg.uninstall
        end
      end

      rm_pin rack
    else
      kegs.each do |keg|
        begin
          f = Formulary.from_rack(rack)
          if f.pinned?
            onoe "#{f.full_name} is pinned. You must unpin it to uninstall."
            break # exit keg loop and move on to next rack
          end
        rescue
          nil
        end

        keg.lock do
          puts "Uninstalling #{keg}... (#{keg.abv})"
          keg.unlink
          keg.uninstall
          rack = keg.rack
          rm_pin rack

          if rack.directory?
            versions = rack.subdirs.map(&:basename)
            puts <<~EOS
              #{keg.name} #{versions.to_sentence} #{(versions.count == 1) ? "is" : "are"} still installed.
              To remove all versions, run:
                brew uninstall --force #{keg.name}
            EOS
          end

          next unless f

          paths = f.pkgetc.find.map(&:to_s) if f.pkgetc.exist?
          if paths.present?
            puts
            opoo <<~EOS
              The following #{f.name} configuration files have not been removed!
              If desired, remove them manually with `rm -rf`:
                #{paths.sort.uniq.join("\n  ")}
            EOS
          end

          unversioned_name = f.name.gsub(/@.+$/, "")
          maybe_paths = Dir.glob("#{f.etc}/*#{unversioned_name}*")
          maybe_paths -= paths if paths.present?
          if maybe_paths.present?
            puts
            opoo <<~EOS
              The following may be #{f.name} configuration files and have not been removed!
              If desired, remove them manually with `rm -rf`:
                #{maybe_paths.sort.uniq.join("\n  ")}
            EOS
          end
        end
      end
    end
  end
rescue MultipleVersionsInstalledError => e
  ofail e
ensure
  # If we delete Cellar/newname, then Cellar/oldname symlink
  # can become broken and we have to remove it.
  if HOMEBREW_CELLAR.directory?
    HOMEBREW_CELLAR.children.each do |rack|
      rack.unlink if rack.symlink? && !rack.resolved_path_exists?
    end
  end
end