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|
|
path.children.select(&:directory?).sort.map do |path|
|
||||||
token = path.basename.to_s
|
token = path.basename.to_s
|
||||||
|
|
||||||
if (tap_path = CaskLoader.tap_paths(token).first)
|
begin
|
||||||
CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
|
if (tap_path = CaskLoader.tap_paths(token).first)
|
||||||
elsif (caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first)
|
CaskLoader::FromTapPathLoader.new(tap_path).load(config: config)
|
||||||
CaskLoader::FromPathLoader.new(caskroom_path).load(config: config)
|
elsif (caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first)
|
||||||
else
|
CaskLoader::FromPathLoader.new(caskroom_path).load(config: config)
|
||||||
CaskLoader.load(token, 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
|
end.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -39,14 +39,7 @@ module Cask
|
|||||||
casks.each do |cask|
|
casks.each do |cask|
|
||||||
odebug "Uninstalling Cask #{cask}"
|
odebug "Uninstalling Cask #{cask}"
|
||||||
|
|
||||||
if cask.installed?
|
raise CaskNotInstalledError, cask if !cask.installed? && !force
|
||||||
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
|
|
||||||
|
|
||||||
Installer.new(cask, **options).uninstall
|
Installer.new(cask, **options).uninstall
|
||||||
|
|
||||||
|
|||||||
@ -32,14 +32,7 @@ module Cask
|
|||||||
casks.each do |cask|
|
casks.each do |cask|
|
||||||
odebug "Zapping Cask #{cask}"
|
odebug "Zapping Cask #{cask}"
|
||||||
|
|
||||||
if cask.installed?
|
raise CaskNotInstalledError, cask if !cask.installed? && !force
|
||||||
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
|
|
||||||
|
|
||||||
Installer.new(cask, verbose: verbose, force: force).zap
|
Installer.new(cask, verbose: verbose, force: force).zap
|
||||||
end
|
end
|
||||||
|
|||||||
@ -148,6 +148,16 @@ module Homebrew
|
|||||||
|
|
||||||
return cask
|
return cask
|
||||||
rescue Cask::CaskUnreadableError => e
|
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)
|
# Need to rescue before `CaskUnavailableError` (superclass of this)
|
||||||
# The cask was found, but there's a problem with its implementation
|
# The cask was found, but there's a problem with its implementation
|
||||||
unreadable_error ||= e
|
unreadable_error ||= e
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user