Class: Cask::Pkg Private

Inherits:
Object show all
Defined in:
cask/pkg.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.

Helper class for uninstalling .pkg installers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_id, command = SystemCommand) ⇒ 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:



20
21
22
23
# File 'cask/pkg.rb', line 20

def initialize(package_id, command = SystemCommand)
  @package_id = package_id
  @command = command
end

Instance Attribute Details

#package_idString (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:



17
18
19
# File 'cask/pkg.rb', line 17

def package_id
  @package_id
end

Class Method Details

.all_matching(regexp, command) ⇒ Array<Pkg>

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:



10
11
12
13
14
# File 'cask/pkg.rb', line 10

def self.all_matching(regexp, command)
  command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map do |package_id|
    new(package_id.chomp, command)
  end
end

Instance Method Details

#forgetvoid

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.

This method returns an undefined value.



60
61
62
63
64
65
66
67
68
# File 'cask/pkg.rb', line 60

def forget
  odebug "Unregistering pkg receipt (aka forgetting)"
  @command.run!(
    "/usr/sbin/pkgutil",
    args:         ["--forget", package_id],
    sudo:         true,
    sudo_as_root: true,
  )
end

#infoObject

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.



99
100
101
102
# File 'cask/pkg.rb', line 99

def info
  @info ||= @command.run!("/usr/sbin/pkgutil", args: ["--pkg-info-plist", package_id])
                    .plist
end

#pkgutil_bom_allArray<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:



86
87
88
89
90
91
92
# File 'cask/pkg.rb', line 86

def pkgutil_bom_all
  @pkgutil_bom_all ||= @command.run!("/usr/sbin/pkgutil", args: ["--files", package_id])
                               .stdout
                               .split("\n")
                               .map { |path| root.join(path) }
                               .reject { MacOS.undeletable?(_1) }
end

#pkgutil_bom_dirsArray<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:



81
82
83
# File 'cask/pkg.rb', line 81

def pkgutil_bom_dirs
  @pkgutil_bom_dirs ||= pkgutil_bom_all.select(&:directory?) - pkgutil_bom_specials
end

#pkgutil_bom_filesArray<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:



71
72
73
# File 'cask/pkg.rb', line 71

def pkgutil_bom_files
  @pkgutil_bom_files ||= pkgutil_bom_all.select(&:file?) - pkgutil_bom_specials
end

#pkgutil_bom_specialsArray<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:



76
77
78
# File 'cask/pkg.rb', line 76

def pkgutil_bom_specials
  @pkgutil_bom_specials ||= pkgutil_bom_all.select { special?(_1) }
end

#rootPathname

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:



95
96
97
# File 'cask/pkg.rb', line 95

def root
  @root ||= Pathname.new(info.fetch("volume")).join(info.fetch("install-location"))
end

#uninstallvoid

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.

This method returns an undefined value.



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
# File 'cask/pkg.rb', line 26

def uninstall
  unless pkgutil_bom_files.empty?
    odebug "Deleting pkg files"
    @command.run!(
      "/usr/bin/xargs",
      args:         ["-0", "--", "/bin/rm", "--"],
      input:        pkgutil_bom_files.join("\0"),
      sudo:         true,
      sudo_as_root: true,
    )
  end

  unless pkgutil_bom_specials.empty?
    odebug "Deleting pkg symlinks and special files"
    @command.run!(
      "/usr/bin/xargs",
      args:         ["-0", "--", "/bin/rm", "--"],
      input:        pkgutil_bom_specials.join("\0"),
      sudo:         true,
      sudo_as_root: true,
    )
  end

  unless pkgutil_bom_dirs.empty?
    odebug "Deleting pkg directories"
    rmdir(deepest_path_first(pkgutil_bom_dirs))
  end

  rmdir(root) unless MacOS.undeletable?(root)

  forget
end