Merge pull request #4315 from reitermarkus/remove-ensure-cache
Remove `Hbc.init`.
This commit is contained in:
commit
343a5b45a9
@ -25,10 +25,3 @@ require "hbc/url"
|
|||||||
require "hbc/utils"
|
require "hbc/utils"
|
||||||
require "hbc/verify"
|
require "hbc/verify"
|
||||||
require "hbc/version"
|
require "hbc/version"
|
||||||
|
|
||||||
module Hbc
|
|
||||||
def self.init
|
|
||||||
Cache.ensure_cache_exists
|
|
||||||
Caskroom.ensure_caskroom_exists
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
@ -5,12 +5,5 @@ module Hbc
|
|||||||
def path
|
def path
|
||||||
@path ||= HOMEBREW_CACHE.join("Cask")
|
@path ||= HOMEBREW_CACHE.join("Cask")
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_cache_exists
|
|
||||||
return if path.exist?
|
|
||||||
|
|
||||||
odebug "Creating Cache at #{path}"
|
|
||||||
path.mkpath
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,10 +9,12 @@ module Hbc
|
|||||||
def ensure_caskroom_exists
|
def ensure_caskroom_exists
|
||||||
return if path.exist?
|
return if path.exist?
|
||||||
|
|
||||||
ohai "Creating Caskroom at #{path}" if $stdout.tty?
|
|
||||||
sudo = !path.parent.writable?
|
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/mkdir", args: ["-p", path], sudo: sudo)
|
||||||
SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo: sudo)
|
SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo: sudo)
|
||||||
@ -21,6 +23,8 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def casks
|
def casks
|
||||||
|
return [] unless path.exist?
|
||||||
|
|
||||||
Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path|
|
Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path|
|
||||||
token = path.basename.to_s
|
token = path.basename.to_s
|
||||||
|
|
||||||
|
@ -88,10 +88,6 @@ module Hbc
|
|||||||
@lookup.fetch(command_name, command_name)
|
@lookup.fetch(command_name, command_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.should_init?(command)
|
|
||||||
command.is_a?(Class) && !command.abstract? && command.needs_init?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.run_command(command, *args)
|
def self.run_command(command, *args)
|
||||||
if command.respond_to?(:run)
|
if command.respond_to?(:run)
|
||||||
# usual case: built-in command verb
|
# usual case: built-in command verb
|
||||||
@ -164,7 +160,6 @@ module Hbc
|
|||||||
MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
|
MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
|
||||||
|
|
||||||
Tap.default_cask_tap.install unless Tap.default_cask_tap.installed?
|
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)
|
self.class.run_command(command, *args)
|
||||||
rescue CaskError, ArgumentError, OptionParser::InvalidOption => e
|
rescue CaskError, ArgumentError, OptionParser::InvalidOption => e
|
||||||
msg = e.message
|
msg = e.message
|
||||||
|
@ -27,10 +27,6 @@ module Hbc
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.run(*args)
|
def self.run(*args)
|
||||||
new(*args).run
|
new(*args).run
|
||||||
end
|
end
|
||||||
|
@ -20,10 +20,6 @@ module Hbc
|
|||||||
odebug "Auditing Cask #{cask}"
|
odebug "Auditing Cask #{cask}"
|
||||||
Auditor.audit(cask, audit_download: download?, check_token_conflicts: token_conflicts?)
|
Auditor.audit(cask, audit_download: download?, check_token_conflicts: token_conflicts?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,10 +8,6 @@ module Hbc
|
|||||||
"cleans up cached downloads and tracker symlinks"
|
"cleans up cached downloads and tracker symlinks"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_reader :cache_location
|
attr_reader :cache_location
|
||||||
|
|
||||||
def initialize(*args, cache_location: Cache.path)
|
def initialize(*args, cache_location: Cache.path)
|
||||||
@ -24,7 +20,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cache_files
|
def cache_files
|
||||||
return [] unless cache_location.exist?
|
return [] unless cache_location.directory?
|
||||||
cache_location.children
|
cache_location.children
|
||||||
.map(&method(:Pathname))
|
.map(&method(:Pathname))
|
||||||
.reject(&method(:outdated?))
|
.reject(&method(:outdated?))
|
||||||
|
@ -62,9 +62,7 @@ module Hbc
|
|||||||
|
|
||||||
path = Pathname.new(user_tilde(Caskroom.path.to_s))
|
path = Pathname.new(user_tilde(Caskroom.path.to_s))
|
||||||
|
|
||||||
if !path.exist?
|
if path.exist? && !path.writable?
|
||||||
add_error "The staging path #{path} does not exist."
|
|
||||||
elsif !path.writable?
|
|
||||||
add_error "The staging path #{path} is not writable by the current user."
|
add_error "The staging path #{path} is not writable by the current user."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,10 +17,6 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.help
|
def self.help
|
||||||
"downloads remote application files to local cache"
|
"downloads remote application files to local cache"
|
||||||
end
|
end
|
||||||
|
@ -27,10 +27,6 @@ module Hbc
|
|||||||
def self.help
|
def self.help
|
||||||
"installs the given Cask"
|
"installs the given Cask"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -49,10 +49,6 @@ module Hbc
|
|||||||
def self.help
|
def self.help
|
||||||
"prints or calculates a given Cask's or URL's appcast checkpoint"
|
"prints or calculates a given Cask's or URL's appcast checkpoint"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,10 +5,6 @@ module Hbc
|
|||||||
|
|
||||||
option "--cleanup", :cleanup, false
|
option "--cleanup", :cleanup, false
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_accessor :commit_range
|
attr_accessor :commit_range
|
||||||
private :commit_range=
|
private :commit_range=
|
||||||
|
|
||||||
|
@ -57,10 +57,6 @@ module Hbc
|
|||||||
def self.help
|
def self.help
|
||||||
"with no args, lists installed Casks; given installed Casks, lists staged files"
|
"with no args, lists installed Casks; given installed Casks, lists staged files"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,10 @@ module Hbc
|
|||||||
Caskroom.casks.select do |cask|
|
Caskroom.casks.select do |cask|
|
||||||
cask.outdated?(greedy?)
|
cask.outdated?(greedy?)
|
||||||
end
|
end
|
||||||
}).select { |cask| cask.outdated?(true) }
|
}).select do |cask|
|
||||||
|
raise CaskNotInstalledError, cask unless cask.installed? || force?
|
||||||
|
cask.outdated?(true)
|
||||||
|
end
|
||||||
|
|
||||||
if outdated_casks.empty?
|
if outdated_casks.empty?
|
||||||
oh1 "No Casks to upgrade"
|
oh1 "No Casks to upgrade"
|
||||||
@ -28,8 +31,6 @@ module Hbc
|
|||||||
|
|
||||||
outdated_casks.each do |old_cask|
|
outdated_casks.each do |old_cask|
|
||||||
odebug "Started upgrade process for Cask #{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?
|
raise CaskUnavailableError.new(old_cask, "The Caskfile is missing!") if old_cask.installed_caskfile.nil?
|
||||||
|
|
||||||
old_cask = CaskLoader.load(old_cask.installed_caskfile)
|
old_cask = CaskLoader.load(old_cask.installed_caskfile)
|
||||||
@ -82,10 +83,6 @@ module Hbc
|
|||||||
def self.help
|
def self.help
|
||||||
"upgrades all outdated casks"
|
"upgrades all outdated casks"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -95,6 +95,8 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
|
tarball_path.dirname.mkpath
|
||||||
|
|
||||||
ohai "Downloading #{@url}"
|
ohai "Downloading #{@url}"
|
||||||
if tarball_path.exist?
|
if tarball_path.exist?
|
||||||
puts "Already downloaded: #{tarball_path}"
|
puts "Already downloaded: #{tarball_path}"
|
||||||
@ -193,6 +195,8 @@ module Hbc
|
|||||||
|
|
||||||
# super does not provide checks for already-existing downloads
|
# super does not provide checks for already-existing downloads
|
||||||
def fetch
|
def fetch
|
||||||
|
cached_location.dirname.mkpath
|
||||||
|
|
||||||
if cached_location.directory?
|
if cached_location.directory?
|
||||||
puts "Already downloaded: #{cached_location}"
|
puts "Already downloaded: #{cached_location}"
|
||||||
else
|
else
|
||||||
|
@ -55,6 +55,8 @@ module Hbc
|
|||||||
def stage
|
def stage
|
||||||
odebug "Hbc::Installer#stage"
|
odebug "Hbc::Installer#stage"
|
||||||
|
|
||||||
|
Caskroom.ensure_caskroom_exists
|
||||||
|
|
||||||
extract_primary_container
|
extract_primary_container
|
||||||
save_caskfile
|
save_caskfile
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
@ -23,7 +23,7 @@ RSpec.shared_context "Homebrew-Cask" do
|
|||||||
begin
|
begin
|
||||||
HOMEBREW_CASK_DIRS.values.each(&:mkpath)
|
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|
|
Tap.default_cask_tap.tap do |tap|
|
||||||
FileUtils.mkdir_p tap.path.dirname
|
FileUtils.mkdir_p tap.path.dirname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user