cmd/untap: fix untapping syntax failure.
If an installed cask is invalid on attempting an untap: it will prevent untapping that cask. Fix this in two ways: one more specific to `untap` and one more generally to other commands too: - specific: only read the actual formulae/casks from the tap we're untapping instead of all of those that are installed - general: rescue more exceptions in `Cask::Caskroom.casks` (like we already do for `Formula.installed`
This commit is contained in:
parent
cd8a9c02cb
commit
beb9799265
@ -22,6 +22,12 @@ module Cask
|
|||||||
end
|
end
|
||||||
private_class_method :paths
|
private_class_method :paths
|
||||||
|
|
||||||
|
# Return all tokens for installed casks.
|
||||||
|
sig { returns(T::Array[String]) }
|
||||||
|
def self.tokens
|
||||||
|
paths.map(&:basename).map(&:to_s)
|
||||||
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def self.any_casks_installed?
|
def self.any_casks_installed?
|
||||||
paths.any?
|
paths.any?
|
||||||
@ -46,18 +52,14 @@ module Cask
|
|||||||
|
|
||||||
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
|
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
|
||||||
def self.casks(config: nil)
|
def self.casks(config: nil)
|
||||||
paths.sort.map do |path|
|
tokens.sort.map do |token|
|
||||||
token = path.basename.to_s
|
CaskLoader.load(token, config: config)
|
||||||
|
rescue TapCaskAmbiguityError
|
||||||
begin
|
tap_path = CaskLoader.tap_paths(token).first
|
||||||
CaskLoader.load(token, config: config)
|
CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
|
||||||
rescue TapCaskAmbiguityError
|
rescue
|
||||||
tap_path = CaskLoader.tap_paths(token).first
|
# Don't blow up because of a single unavailable cask.
|
||||||
CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
|
nil
|
||||||
rescue CaskUnavailableError
|
|
||||||
# Don't blow up because of a single unavailable cask.
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
@ -19,15 +19,45 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def untap
|
def untap
|
||||||
args = untap_args.parse
|
args = untap_args.parse
|
||||||
|
|
||||||
args.named.to_installed_taps.each do |tap|
|
args.named.to_installed_taps.each do |tap|
|
||||||
odie "Untapping #{tap} is not allowed" if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api?
|
odie "Untapping #{tap} is not allowed" if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
|
||||||
if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && tap != "homebrew/cask")
|
if Homebrew::EnvConfig.no_install_from_api? || (!tap.core_tap? && !tap.core_cask_tap?)
|
||||||
installed_tap_formulae = Formula.installed.select { |formula| formula.tap == tap }
|
installed_formula_names = T.let(nil, T.nilable(T::Set[String]))
|
||||||
installed_tap_casks = Cask::Caskroom.casks.select { |cask| cask.tap == tap }
|
installed_tap_formulae = tap.formula_names.map do |formula_name|
|
||||||
|
# initialise lazily in case there's no formulae in this tap
|
||||||
|
installed_formula_names ||= Set.new(Formula.installed_formula_names)
|
||||||
|
next unless installed_formula_names.include?(formula_name)
|
||||||
|
|
||||||
|
formula = begin
|
||||||
|
Formulary.factory("#{tap.name}/#{formula_name}")
|
||||||
|
rescue
|
||||||
|
# Don't blow up because of a single unavailable formula.
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
formula if formula.any_version_installed?
|
||||||
|
end.compact
|
||||||
|
|
||||||
|
installed_cask_tokens = T.let(nil, T.nilable(T::Set[String]))
|
||||||
|
installed_tap_casks = tap.cask_tokens.map do |cask_token|
|
||||||
|
# initialise lazily in case there's no casks in this tap
|
||||||
|
installed_cask_tokens ||= Set.new(Cask::Caskroom.tokens)
|
||||||
|
next unless installed_cask_tokens.include?(cask_token)
|
||||||
|
|
||||||
|
cask = begin
|
||||||
|
Cask::CaskLoader.load("#{tap.name}/#{cask_token}")
|
||||||
|
rescue
|
||||||
|
# Don't blow up because of a single unavailable cask.
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
cask if cask.installed?
|
||||||
|
end.compact
|
||||||
|
|
||||||
if installed_tap_formulae.present? || installed_tap_casks.present?
|
if installed_tap_formulae.present? || installed_tap_casks.present?
|
||||||
installed_names = (installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n")
|
installed_names = (installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n")
|
||||||
|
|||||||
@ -1950,6 +1950,13 @@ class Formula
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# An array of all currently installed formula names.
|
||||||
|
# @private
|
||||||
|
sig { returns(T::Array[String]) }
|
||||||
|
def self.installed_formula_names
|
||||||
|
racks.map(&:basename).map(&:to_s)
|
||||||
|
end
|
||||||
|
|
||||||
# An array of all installed {Formula}
|
# An array of all installed {Formula}
|
||||||
# @private
|
# @private
|
||||||
def self.installed
|
def self.installed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user