diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index efce21391e..9c8c67f518 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cache.rb b/Library/Homebrew/cask/lib/hbc/cache.rb index 461ce2c84e..96260b83ff 100644 --- a/Library/Homebrew/cask/lib/hbc/cache.rb +++ b/Library/Homebrew/cask/lib/hbc/cache.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb index 4ed4a2b7a5..cd3e1d52b9 100644 --- a/Library/Homebrew/cask/lib/hbc/caskroom.rb +++ b/Library/Homebrew/cask/lib/hbc/caskroom.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index 57cec17469..b75d5e63de 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb index 2cfe3c467d..e6313b5fc5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb @@ -27,10 +27,6 @@ module Hbc nil end - def self.needs_init? - false - end - def self.run(*args) new(*args).run end diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb index 2b89a8d2c3..c1bb5bcd8c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb index 15a85d123b..1553d8e85d 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb @@ -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?)) diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index e60103d290..63edf2d55c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb index 12c794f5f6..f76927297c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index d8f148b1ba..31d90f60ef 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -27,10 +27,6 @@ module Hbc def self.help "installs the given Cask" end - - def self.needs_init? - true - end end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb index a538ffd8c3..a88d1fc170 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb index f06e2acc58..eadd8e2839 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb @@ -5,10 +5,6 @@ module Hbc option "--cleanup", :cleanup, false - def self.needs_init? - true - end - attr_accessor :commit_range private :commit_range= diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 788b0eede5..916860e7e2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb index 3969546712..e0589eb0d0 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb index edcab1d320..44ef287b70 100644 --- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb +++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb @@ -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 diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 90e4c286d4..eb55c9c941 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -55,6 +55,8 @@ module Hbc def stage odebug "Hbc::Installer#stage" + Caskroom.ensure_caskroom_exists + extract_primary_container save_caskfile rescue StandardError => e diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index 62e682966b..e021eb3f7e 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -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