Spec-Zone.ru › Homebrew

Class: Cask::Pkg Private

Inherits:
Object
  • Object
  • Cask::Pkg
show all
Includes:
Utils::Output::Mixin
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

  • #package_id ⇒ String readonly private

Class Method Summary collapse

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

Instance Method Summary collapse

  • #forget ⇒ void private
  • #info ⇒ T.untyped private
  • #initialize(package_id, command = SystemCommand) ⇒ void constructor private
  • #pkgutil_bom_all ⇒ Array<Pathname> private
  • #pkgutil_bom_dirs ⇒ Array<Pathname> private
  • #pkgutil_bom_files ⇒ Array<Pathname> private
  • #pkgutil_bom_specials ⇒ Array<Pathname> private
  • #root ⇒ Pathname private
  • #uninstall ⇒ void private

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

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:

  • package_id (String)
  • command (T.class_of(SystemCommand)) (defaults to: SystemCommand)


23
24
25
26
# File 'cask/pkg.rb', line 23

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

Instance Attribute Details

#package_id ⇒ String (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:

  • (String)


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

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:

  • regexp (String)
  • command (T.class_of(SystemCommand))

Returns:

  • (Array<Pkg>)


13
14
15
16
17
# File 'cask/pkg.rb', line 13

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

#forget ⇒ 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.

This method returns an undefined value.



63
64
65
66
67
68
69
70
71
# File 'cask/pkg.rb', line 63

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

#info ⇒ T.untyped

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:

  • (T.untyped)


108
109
110
# File 'cask/pkg.rb', line 108

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

#pkgutil_bom_all ⇒ Array<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:

  • (Array<Pathname>)


91
92
93
94
95
96
97
98
99
100
# File 'cask/pkg.rb', line 91

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

#pkgutil_bom_dirs ⇒ Array<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:

  • (Array<Pathname>)


85
86
87
88
# File 'cask/pkg.rb', line 85

def pkgutil_bom_dirs
  @pkgutil_bom_dirs ||= T.let(pkgutil_bom_all.select(&:directory?) - pkgutil_bom_specials,
                              T.nilable(T::Array[Pathname]))
end

#pkgutil_bom_files ⇒ Array<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:

  • (Array<Pathname>)


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

def pkgutil_bom_files
  @pkgutil_bom_files ||= T.let(pkgutil_bom_all.select(&:file?) - pkgutil_bom_specials,
                               T.nilable(T::Array[Pathname]))
end

#pkgutil_bom_specials ⇒ Array<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:

  • (Array<Pathname>)


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

def pkgutil_bom_specials
  @pkgutil_bom_specials ||= T.let(pkgutil_bom_all.select { special?(it) }, T.nilable(T::Array[Pathname]))
end

#root ⇒ 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:

  • (Pathname)


103
104
105
# File 'cask/pkg.rb', line 103

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

#uninstall ⇒ 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.

This method returns an undefined value.



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

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

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/Cask/Pkg.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API