Remove the need for ensure_cache_exists.

This commit is contained in:
Markus Reiter 2018-06-09 10:41:14 +02:00
parent 9ebcef785e
commit b2f67c6d77
6 changed files with 6 additions and 18 deletions

View File

@ -28,7 +28,6 @@ require "hbc/version"
module Hbc module Hbc
def self.init def self.init
Cache.ensure_cache_exists
Caskroom.ensure_caskroom_exists Caskroom.ensure_caskroom_exists
end end
end end

View File

@ -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

View File

@ -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?))

View File

@ -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

View File

@ -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

View File

@ -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, Hbc::Caskroom.path].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