Merge pull request #4315 from reitermarkus/remove-ensure-cache

Remove `Hbc.init`.
This commit is contained in:
Markus Reiter 2018-06-11 04:53:42 +02:00 committed by GitHub
commit 343a5b45a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 19 additions and 65 deletions

View File

@ -25,10 +25,3 @@ require "hbc/url"
require "hbc/utils"
require "hbc/verify"
require "hbc/version"
module Hbc
def self.init
Cache.ensure_cache_exists
Caskroom.ensure_caskroom_exists
end
end

View File

@ -5,12 +5,5 @@ module Hbc
def path
@path ||= HOMEBREW_CACHE.join("Cask")
end
def ensure_cache_exists
return if path.exist?
odebug "Creating Cache at #{path}"
path.mkpath
end
end
end

View File

@ -9,10 +9,12 @@ module Hbc
def ensure_caskroom_exists
return if path.exist?
ohai "Creating Caskroom at #{path}" if $stdout.tty?
sudo = !path.parent.writable?
ohai "We'll set permissions properly so we won't need sudo in the future" if $stdout.tty? && sudo
if sudo && !ENV.key?("SUDO_ASKPASS") && $stdout.tty?
ohai "Creating Caskroom at #{path}"
ohai "We'll set permissions properly so we won't need sudo in the future."
end
SystemCommand.run("/bin/mkdir", args: ["-p", path], sudo: sudo)
SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo: sudo)
@ -21,6 +23,8 @@ module Hbc
end
def casks
return [] unless path.exist?
Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path|
token = path.basename.to_s

View File

@ -88,10 +88,6 @@ module Hbc
@lookup.fetch(command_name, command_name)
end
def self.should_init?(command)
command.is_a?(Class) && !command.abstract? && command.needs_init?
end
def self.run_command(command, *args)
if command.respond_to?(:run)
# usual case: built-in command verb
@ -164,7 +160,6 @@ module Hbc
MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
Tap.default_cask_tap.install unless Tap.default_cask_tap.installed?
Hbc.init if self.class.should_init?(command)
self.class.run_command(command, *args)
rescue CaskError, ArgumentError, OptionParser::InvalidOption => e
msg = e.message

View File

@ -27,10 +27,6 @@ module Hbc
nil
end
def self.needs_init?
false
end
def self.run(*args)
new(*args).run
end

View File

@ -20,10 +20,6 @@ module Hbc
odebug "Auditing Cask #{cask}"
Auditor.audit(cask, audit_download: download?, check_token_conflicts: token_conflicts?)
end
def self.needs_init?
true
end
end
end
end

View File

@ -8,10 +8,6 @@ module Hbc
"cleans up cached downloads and tracker symlinks"
end
def self.needs_init?
true
end
attr_reader :cache_location
def initialize(*args, cache_location: Cache.path)
@ -24,7 +20,7 @@ module Hbc
end
def cache_files
return [] unless cache_location.exist?
return [] unless cache_location.directory?
cache_location.children
.map(&method(:Pathname))
.reject(&method(:outdated?))

View File

@ -62,9 +62,7 @@ module Hbc
path = Pathname.new(user_tilde(Caskroom.path.to_s))
if !path.exist?
add_error "The staging path #{path} does not exist."
elsif !path.writable?
if path.exist? && !path.writable?
add_error "The staging path #{path} is not writable by the current user."
end

View File

@ -17,10 +17,6 @@ module Hbc
end
end
def self.needs_init?
true
end
def self.help
"downloads remote application files to local cache"
end

View File

@ -27,10 +27,6 @@ module Hbc
def self.help
"installs the given Cask"
end
def self.needs_init?
true
end
end
end
end

View File

@ -49,10 +49,6 @@ module Hbc
def self.help
"prints or calculates a given Cask's or URL's appcast checkpoint"
end
def self.needs_init?
true
end
end
end
end

View File

@ -5,10 +5,6 @@ module Hbc
option "--cleanup", :cleanup, false
def self.needs_init?
true
end
attr_accessor :commit_range
private :commit_range=

View File

@ -57,10 +57,6 @@ module Hbc
def self.help
"with no args, lists installed Casks; given installed Casks, lists staged files"
end
def self.needs_init?
true
end
end
end
end

View File

@ -16,7 +16,10 @@ module Hbc
Caskroom.casks.select do |cask|
cask.outdated?(greedy?)
end
}).select { |cask| cask.outdated?(true) }
}).select do |cask|
raise CaskNotInstalledError, cask unless cask.installed? || force?
cask.outdated?(true)
end
if outdated_casks.empty?
oh1 "No Casks to upgrade"
@ -28,8 +31,6 @@ module Hbc
outdated_casks.each do |old_cask|
odebug "Started upgrade process for Cask #{old_cask}"
raise CaskNotInstalledError, old_cask unless old_cask.installed? || force?
raise CaskUnavailableError.new(old_cask, "The Caskfile is missing!") if old_cask.installed_caskfile.nil?
old_cask = CaskLoader.load(old_cask.installed_caskfile)
@ -82,10 +83,6 @@ module Hbc
def self.help
"upgrades all outdated casks"
end
def self.needs_init?
true
end
end
end
end

View File

@ -95,6 +95,8 @@ module Hbc
end
def fetch
tarball_path.dirname.mkpath
ohai "Downloading #{@url}"
if tarball_path.exist?
puts "Already downloaded: #{tarball_path}"
@ -193,6 +195,8 @@ module Hbc
# super does not provide checks for already-existing downloads
def fetch
cached_location.dirname.mkpath
if cached_location.directory?
puts "Already downloaded: #{cached_location}"
else

View File

@ -55,6 +55,8 @@ module Hbc
def stage
odebug "Hbc::Installer#stage"
Caskroom.ensure_caskroom_exists
extract_primary_container
save_caskfile
rescue StandardError => e

View File

@ -23,7 +23,7 @@ RSpec.shared_context "Homebrew-Cask" do
begin
HOMEBREW_CASK_DIRS.values.each(&:mkpath)
[Hbc::Config.global.binarydir, Hbc::Caskroom.path, Hbc::Cache.path].each(&:mkpath)
[Hbc::Config.global.binarydir].each(&:mkpath)
Tap.default_cask_tap.tap do |tap|
FileUtils.mkdir_p tap.path.dirname