Merge pull request #13289 from Homebrew/handle_broken_casks
Fix handling unreadable casks
This commit is contained in:
commit
b5f7e7ff11
@ -46,14 +46,19 @@ module Cask
|
||||
path.children.select(&:directory?).sort.map do |path|
|
||||
token = path.basename.to_s
|
||||
|
||||
if (tap_path = CaskLoader.tap_paths(token).first)
|
||||
CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
|
||||
elsif (caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first)
|
||||
CaskLoader::FromPathLoader.new(caskroom_path).load(config: config)
|
||||
else
|
||||
CaskLoader.load(token, config: config)
|
||||
begin
|
||||
if (tap_path = CaskLoader.tap_paths(token).first)
|
||||
CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
|
||||
elsif (caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first)
|
||||
CaskLoader::FromPathLoader.new(caskroom_path).load(config: config)
|
||||
else
|
||||
CaskLoader.load(token, config: config)
|
||||
end
|
||||
rescue CaskUnavailableError
|
||||
# Don't blow up because of a single unavailable cask.
|
||||
nil
|
||||
end
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -39,14 +39,7 @@ module Cask
|
||||
casks.each do |cask|
|
||||
odebug "Uninstalling Cask #{cask}"
|
||||
|
||||
if cask.installed?
|
||||
if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
|
||||
# Use the same cask file that was used for installation, if possible.
|
||||
cask = CaskLoader.load(installed_caskfile)
|
||||
end
|
||||
else
|
||||
raise CaskNotInstalledError, cask unless force
|
||||
end
|
||||
raise CaskNotInstalledError, cask if !cask.installed? && !force
|
||||
|
||||
Installer.new(cask, **options).uninstall
|
||||
|
||||
|
||||
@ -32,14 +32,7 @@ module Cask
|
||||
casks.each do |cask|
|
||||
odebug "Zapping Cask #{cask}"
|
||||
|
||||
if cask.installed?
|
||||
if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
|
||||
# Use the same cask file that was used for installation, if possible.
|
||||
cask = CaskLoader.load(installed_caskfile)
|
||||
end
|
||||
else
|
||||
raise CaskNotInstalledError, cask unless force
|
||||
end
|
||||
raise CaskNotInstalledError, cask if !cask.installed? && !force
|
||||
|
||||
Installer.new(cask, verbose: verbose, force: force).zap
|
||||
end
|
||||
|
||||
@ -148,6 +148,16 @@ module Homebrew
|
||||
|
||||
return cask
|
||||
rescue Cask::CaskUnreadableError => e
|
||||
# If we're trying to get a keg-like Cask, do our best to handle it
|
||||
# not being readable and return something that can be used.
|
||||
if [:latest_kegs, :default_kegs, :kegs].include?(method)
|
||||
cask_version = Cask::Cask.new(name, config: config).versions.first
|
||||
cask = Cask::Cask.new(name, config: config) do
|
||||
version cask_version if cask_version
|
||||
end
|
||||
return cask
|
||||
end
|
||||
|
||||
# Need to rescue before `CaskUnavailableError` (superclass of this)
|
||||
# The cask was found, but there's a problem with its implementation
|
||||
unreadable_error ||= e
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user