From b2f67c6d776170b64a2963e175f96f23eef4646e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 9 Jun 2018 10:41:14 +0200 Subject: [PATCH] Remove the need for `ensure_cache_exists`. --- Library/Homebrew/cask/lib/hbc.rb | 1 - Library/Homebrew/cask/lib/hbc/cache.rb | 7 ------- Library/Homebrew/cask/lib/hbc/cli/cleanup.rb | 6 +----- Library/Homebrew/cask/lib/hbc/cli/fetch.rb | 4 ---- Library/Homebrew/cask/lib/hbc/download_strategy.rb | 4 ++++ .../support/helper/spec/shared_context/homebrew_cask.rb | 2 +- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index efce21391e..ffed20f2f4 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -28,7 +28,6 @@ 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/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/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/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/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index 62e682966b..62613fcf1a 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, Hbc::Caskroom.path].each(&:mkpath) Tap.default_cask_tap.tap do |tap| FileUtils.mkdir_p tap.path.dirname