Use saved cask config for reinstall/upgrade/uninstall.

This commit is contained in:
Markus Reiter 2019-02-03 13:03:16 +01:00
parent fda6e0cab3
commit 190ff7558a
8 changed files with 38 additions and 18 deletions

View File

@ -94,11 +94,14 @@ module Cask
[executable, arguments]
end
attr_reader :cask, :config
attr_reader :cask
def initialize(cask)
@cask = cask
@config = cask.config
end
def config
cask.config
end
def to_s

View File

@ -11,7 +11,7 @@ module Cask
extend Searchable
include Metadata
attr_reader :token, :sourcefile_path
attr_reader :token, :sourcefile_path, :config
def self.each
return to_enum unless block_given?
@ -31,15 +31,21 @@ module Cask
@tap
end
def initialize(token, sourcefile_path: nil, tap: nil, config: nil, &block)
def initialize(token, sourcefile_path: nil, tap: nil, &block)
@token = token
@sourcefile_path = sourcefile_path
@tap = tap
@config = config
@dsl = DSL.new(self)
return unless block_given?
@block = block
self.config = Config.for_cask(self)
end
@dsl.instance_eval(&block)
def config=(config)
@config = config
@dsl = DSL.new(self)
return unless @block
@dsl.instance_eval(&@block)
@dsl.language_eval
end
@ -77,14 +83,14 @@ module Cask
metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb")
end
def config
@config ||= Config.for_cask(self)
end
def config_path
metadata_master_container_path/"dirs.json"
end
def caskroom_path
@caskroom_path ||= Caskroom.path.join(token)
end
def outdated?(greedy = false)
!outdated_versions(greedy).empty?
end

View File

@ -1,3 +1,5 @@
require "cask/config"
module Cask
class Cmd
class Upgrade < AbstractCommand
@ -44,13 +46,17 @@ module Cask
old_cask = CaskLoader.load(old_cask.installed_caskfile)
old_config = old_cask.config
old_cask_installer =
Installer.new(old_cask, binaries: binaries?,
verbose: verbose?,
force: force?,
upgrade: true)
new_cask = CaskLoader.load(old_cask.to_s)
new_cask = CaskLoader.load(old_cask.token)
new_cask.config = Config.global.merge(old_config)
new_cask_installer =
Installer.new(new_cask, binaries: binaries?,

View File

@ -88,7 +88,7 @@ module Cask
end
def merge(other)
self.class.new(**other.explicit.merge(explicit))
self.class.new(explicit: other.explicit.merge(explicit))
end
def to_json(*args)

View File

@ -57,7 +57,6 @@ module Cask
:appcast,
:artifacts,
:auto_updates,
:caskroom_path,
:caveats,
:conflicts_with,
:container,
@ -226,7 +225,7 @@ module Cask
end
def caskroom_path
@caskroom_path ||= Caskroom.path.join(token)
@cask.caskroom_path
end
def staged_path

View File

@ -4,6 +4,7 @@ require "formula_installer"
require "unpack_strategy"
require "cask/cask_dependencies"
require "cask/config"
require "cask/download"
require "cask/staged"
require "cask/verify"
@ -79,6 +80,8 @@ module Cask
def install
odebug "Cask::Installer#install"
old_config = @cask.config
if @cask.installed? && !force? && !reinstall? && !upgrade?
raise CaskAlreadyInstalledError, @cask
end
@ -92,6 +95,9 @@ module Cask
oh1 "Installing Cask #{Formatter.identifier(@cask)}"
opoo "macOS's Gatekeeper has been disabled for this Cask" unless quarantine?
stage
@cask.config = Config.global.merge(old_config)
install_artifacts
unless @cask.tap&.private?

View File

@ -2,7 +2,7 @@ describe Cask::Artifact::Installer, :cask do
subject(:installer) { described_class.new(cask, **args) }
let(:staged_path) { mktmpdir }
let(:cask) { instance_double(Cask::Cask, staged_path: staged_path, config: nil) }
let(:cask) { instance_double(Cask::Cask, staged_path: staged_path) }
let(:command) { SystemCommand }

View File

@ -1,7 +1,7 @@
require_relative "shared_examples/invalid_option"
describe Cask::Cmd::Audit, :cask do
let(:cask) { Cask::Cask.new(nil) }
let(:cask) { Cask::Cask.new("cask") }
it_behaves_like "a command that handles invalid options"