Merge pull request #14506 from Rylan12/fix-missing-cask
Fix cask not found error when upgrading certain casks
This commit is contained in:
commit
e466a68c56
@ -19,7 +19,7 @@ module Cask
|
|||||||
extend Searchable
|
extend Searchable
|
||||||
include Metadata
|
include Metadata
|
||||||
|
|
||||||
attr_reader :token, :sourcefile_path, :source, :config, :default_config
|
attr_reader :token, :sourcefile_path, :source, :config, :default_config, :loaded_from_api
|
||||||
|
|
||||||
attr_accessor :download, :allow_reassignment
|
attr_accessor :download, :allow_reassignment
|
||||||
|
|
||||||
@ -44,12 +44,14 @@ module Cask
|
|||||||
@tap
|
@tap
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(token, sourcefile_path: nil, source: nil, tap: nil, config: nil, allow_reassignment: false, &block)
|
def initialize(token, sourcefile_path: nil, source: nil, tap: nil, config: nil,
|
||||||
|
allow_reassignment: false, loaded_from_api: false, &block)
|
||||||
@token = token
|
@token = token
|
||||||
@sourcefile_path = sourcefile_path
|
@sourcefile_path = sourcefile_path
|
||||||
@source = source
|
@source = source
|
||||||
@tap = tap
|
@tap = tap
|
||||||
@allow_reassignment = allow_reassignment
|
@allow_reassignment = allow_reassignment
|
||||||
|
@loaded_from_api = loaded_from_api
|
||||||
@block = block
|
@block = block
|
||||||
|
|
||||||
@default_config = config || Config.new
|
@default_config = config || Config.new
|
||||||
@ -133,7 +135,10 @@ module Cask
|
|||||||
|
|
||||||
def installed_caskfile
|
def installed_caskfile
|
||||||
installed_version = timestamped_versions.last
|
installed_version = timestamped_versions.last
|
||||||
metadata_main_container_path.join(*installed_version, "Casks", "#{token}.rb")
|
caskfile_dir = metadata_main_container_path.join(*installed_version, "Casks")
|
||||||
|
return caskfile_dir.join("#{token}.json") if caskfile_dir.join("#{token}.json").exist?
|
||||||
|
|
||||||
|
caskfile_dir.join("#{token}.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def config_path
|
def config_path
|
||||||
|
|||||||
@ -51,7 +51,7 @@ module Cask
|
|||||||
class FromPathLoader < FromContentLoader
|
class FromPathLoader < FromContentLoader
|
||||||
def self.can_load?(ref)
|
def self.can_load?(ref)
|
||||||
path = Pathname(ref)
|
path = Pathname(ref)
|
||||||
path.extname == ".rb" && path.expand_path.exist?
|
%w[.rb .json].include?(path.extname) && path.expand_path.exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :token, :path
|
attr_reader :token, :path
|
||||||
@ -59,7 +59,7 @@ module Cask
|
|||||||
def initialize(path) # rubocop:disable Lint/MissingSuper
|
def initialize(path) # rubocop:disable Lint/MissingSuper
|
||||||
path = Pathname(path).expand_path
|
path = Pathname(path).expand_path
|
||||||
|
|
||||||
@token = path.basename(".rb").to_s
|
@token = path.basename(path.extname).to_s
|
||||||
@path = path
|
@path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -71,6 +71,10 @@ module Cask
|
|||||||
@content = path.read(encoding: "UTF-8")
|
@content = path.read(encoding: "UTF-8")
|
||||||
@config = config
|
@config = config
|
||||||
|
|
||||||
|
if path.extname == ".json"
|
||||||
|
return FromAPILoader.new(token, from_json: JSON.parse(@content)).load(config: config)
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
instance_eval(content, path).tap do |cask|
|
instance_eval(content, path).tap do |cask|
|
||||||
raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask)
|
raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask)
|
||||||
@ -201,13 +205,15 @@ module Cask
|
|||||||
Homebrew::API::Cask.all_casks.key?(token)
|
Homebrew::API::Cask.all_casks.key?(token)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(token)
|
def initialize(token, from_json: nil)
|
||||||
@token = token.delete_prefix("homebrew/cask/")
|
@token = token.delete_prefix("homebrew/cask/")
|
||||||
@path = CaskLoader.default_path(token)
|
@path = CaskLoader.default_path(token)
|
||||||
|
@from_json = from_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def load(config:)
|
def load(config:)
|
||||||
json_cask = Homebrew::API::Cask.all_casks[token]
|
json_cask = @from_json || Homebrew::API::Cask.all_casks[token]
|
||||||
|
cask_source = JSON.pretty_generate(json_cask)
|
||||||
|
|
||||||
if (bottle_tag = ::Utils::Bottles.tag.to_s.presence) &&
|
if (bottle_tag = ::Utils::Bottles.tag.to_s.presence) &&
|
||||||
(variations = json_cask["variations"].presence) &&
|
(variations = json_cask["variations"].presence) &&
|
||||||
@ -230,7 +236,7 @@ module Cask
|
|||||||
|
|
||||||
tap = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")
|
tap = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")
|
||||||
|
|
||||||
Cask.new(token, tap: tap, source: cask_source, config: config) do
|
Cask.new(token, tap: tap, source: cask_source, config: config, loaded_from_api: true) do
|
||||||
version json_cask[:version]
|
version json_cask[:version]
|
||||||
|
|
||||||
if json_cask[:sha256] == "no_check"
|
if json_cask[:sha256] == "no_check"
|
||||||
|
|||||||
@ -386,7 +386,8 @@ module Cask
|
|||||||
|
|
||||||
return if @cask.source.blank?
|
return if @cask.source.blank?
|
||||||
|
|
||||||
(metadata_subdir/"#{@cask.token}.rb").write @cask.source
|
extension = @cask.loaded_from_api ? "json" : "rb"
|
||||||
|
(metadata_subdir/"#{@cask.token}.#{extension}").write @cask.source
|
||||||
old_savedir&.rmtree
|
old_savedir&.rmtree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user