Add type signatures to Cask::Pkg.
This commit is contained in:
parent
845887914e
commit
0b6c31fc70
@ -8,19 +8,25 @@ module Cask
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
class Pkg
|
class Pkg
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
|
sig { params(regexp: String, command: T.class_of(SystemCommand)).returns(T::Array[Pkg]) }
|
||||||
def self.all_matching(regexp, command)
|
def self.all_matching(regexp, command)
|
||||||
command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map do |package_id|
|
command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map do |package_id|
|
||||||
new(package_id.chomp, command)
|
new(package_id.chomp, command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
attr_reader :package_id
|
attr_reader :package_id
|
||||||
|
|
||||||
|
sig { params(package_id: String, command: T.class_of(SystemCommand)).void }
|
||||||
def initialize(package_id, command = SystemCommand)
|
def initialize(package_id, command = SystemCommand)
|
||||||
@package_id = package_id
|
@package_id = package_id
|
||||||
@command = command
|
@command = command
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def uninstall
|
def uninstall
|
||||||
unless pkgutil_bom_files.empty?
|
unless pkgutil_bom_files.empty?
|
||||||
odebug "Deleting pkg files"
|
odebug "Deleting pkg files"
|
||||||
@ -65,23 +71,28 @@ module Cask
|
|||||||
forget
|
forget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def forget
|
def forget
|
||||||
odebug "Unregistering pkg receipt (aka forgetting)"
|
odebug "Unregistering pkg receipt (aka forgetting)"
|
||||||
@command.run!("/usr/sbin/pkgutil", args: ["--forget", package_id], sudo: true)
|
@command.run!("/usr/sbin/pkgutil", args: ["--forget", package_id], sudo: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def pkgutil_bom_files
|
def pkgutil_bom_files
|
||||||
@pkgutil_bom_files ||= pkgutil_bom_all.select(&:file?) - pkgutil_bom_specials
|
@pkgutil_bom_files ||= pkgutil_bom_all.select(&:file?) - pkgutil_bom_specials
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def pkgutil_bom_specials
|
def pkgutil_bom_specials
|
||||||
@pkgutil_bom_specials ||= pkgutil_bom_all.select(&method(:special?))
|
@pkgutil_bom_specials ||= pkgutil_bom_all.select(&method(:special?))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def pkgutil_bom_dirs
|
def pkgutil_bom_dirs
|
||||||
@pkgutil_bom_dirs ||= pkgutil_bom_all.select(&:directory?) - pkgutil_bom_specials
|
@pkgutil_bom_dirs ||= pkgutil_bom_all.select(&:directory?) - pkgutil_bom_specials
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Pathname]) }
|
||||||
def pkgutil_bom_all
|
def pkgutil_bom_all
|
||||||
@pkgutil_bom_all ||= @command.run!("/usr/sbin/pkgutil", args: ["--files", package_id])
|
@pkgutil_bom_all ||= @command.run!("/usr/sbin/pkgutil", args: ["--files", package_id])
|
||||||
.stdout
|
.stdout
|
||||||
@ -90,6 +101,7 @@ module Cask
|
|||||||
.reject(&MacOS.public_method(:undeletable?))
|
.reject(&MacOS.public_method(:undeletable?))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Pathname) }
|
||||||
def root
|
def root
|
||||||
@root ||= Pathname.new(info.fetch("volume")).join(info.fetch("install-location"))
|
@root ||= Pathname.new(info.fetch("volume")).join(info.fetch("install-location"))
|
||||||
end
|
end
|
||||||
@ -101,10 +113,12 @@ module Cask
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { params(path: Pathname).returns(T::Boolean) }
|
||||||
def special?(path)
|
def special?(path)
|
||||||
path.symlink? || path.chardev? || path.blockdev?
|
path.symlink? || path.chardev? || path.blockdev?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(path: Pathname).void }
|
||||||
def rmdir(path)
|
def rmdir(path)
|
||||||
return unless path.children.empty?
|
return unless path.children.empty?
|
||||||
|
|
||||||
@ -115,7 +129,8 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_full_permissions(path)
|
sig { params(path: Pathname, _block: T.proc.void).void }
|
||||||
|
def with_full_permissions(path, &_block)
|
||||||
original_mode = (path.stat.mode % 01000).to_s(8)
|
original_mode = (path.stat.mode % 01000).to_s(8)
|
||||||
original_flags = @command.run!("/usr/bin/stat", args: ["-f", "%Of", "--", path]).stdout.chomp
|
original_flags = @command.run!("/usr/bin/stat", args: ["-f", "%Of", "--", path]).stdout.chomp
|
||||||
|
|
||||||
@ -128,10 +143,12 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(paths: T::Array[Pathname]).returns(T::Array[Pathname]) }
|
||||||
def deepest_path_first(paths)
|
def deepest_path_first(paths)
|
||||||
paths.sort_by { |path| -path.to_s.split(File::SEPARATOR).count }
|
paths.sort_by { |path| -path.to_s.split(File::SEPARATOR).count }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(dir: Pathname).void }
|
||||||
def clean_ds_store(dir)
|
def clean_ds_store(dir)
|
||||||
return unless (ds_store = dir.join(".DS_Store")).exist?
|
return unless (ds_store = dir.join(".DS_Store")).exist?
|
||||||
|
|
||||||
@ -140,12 +157,14 @@ module Cask
|
|||||||
|
|
||||||
# Some packages leave broken symlinks around; we clean them out before
|
# Some packages leave broken symlinks around; we clean them out before
|
||||||
# attempting to `rmdir` to prevent extra cruft from accumulating.
|
# attempting to `rmdir` to prevent extra cruft from accumulating.
|
||||||
|
sig { params(dir: Pathname).void }
|
||||||
def clean_broken_symlinks(dir)
|
def clean_broken_symlinks(dir)
|
||||||
dir.children.select(&method(:broken_symlink?)).each do |path|
|
dir.children.select(&method(:broken_symlink?)).each do |path|
|
||||||
@command.run!("/bin/rm", args: ["--", path], sudo: true)
|
@command.run!("/bin/rm", args: ["--", path], sudo: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(path: Pathname).returns(T::Boolean) }
|
||||||
def broken_symlink?(path)
|
def broken_symlink?(path)
|
||||||
path.symlink? && !path.exist?
|
path.symlink? && !path.exist?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,4 +4,8 @@ class Pathname
|
|||||||
# https://github.com/sorbet/sorbet/pull/3676
|
# https://github.com/sorbet/sorbet/pull/3676
|
||||||
sig { params(p1: T.any(String, Pathname), p2: String).returns(T::Array[Pathname]) }
|
sig { params(p1: T.any(String, Pathname), p2: String).returns(T::Array[Pathname]) }
|
||||||
def self.glob(p1, p2 = T.unsafe(nil)); end
|
def self.glob(p1, p2 = T.unsafe(nil)); end
|
||||||
|
|
||||||
|
# https://github.com/sorbet/sorbet/pull/3678
|
||||||
|
sig { params(with_directory: T::Boolean).returns(T::Array[Pathname]) }
|
||||||
|
def children(with_directory = true); end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user