Merge pull request #4607 from reitermarkus/merge-cask-download-strategies
Use normal download strategies for casks.
This commit is contained in:
commit
8e65d035b3
@ -22,13 +22,9 @@ module Hbc
|
|||||||
attr_accessor :downloaded_path
|
attr_accessor :downloaded_path
|
||||||
|
|
||||||
def downloader
|
def downloader
|
||||||
@downloader ||= case cask.url.using
|
@downloader ||= begin
|
||||||
when :svn
|
strategy = DownloadStrategyDetector.detect(cask.url.to_s, cask.url.using)
|
||||||
SubversionDownloadStrategy.new(cask)
|
strategy.new(cask.url.to_s, cask.token, cask.version, cache: Cache.path, **cask.url.specs)
|
||||||
when :post
|
|
||||||
CurlPostDownloadStrategy.new(cask)
|
|
||||||
else
|
|
||||||
CurlDownloadStrategy.new(cask)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,7 +33,8 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
self.downloaded_path = downloader.fetch
|
downloader.fetch
|
||||||
|
@downloaded_path = downloader.cached_location
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
raise CaskError, "Download failed on Cask '#{cask}' with message: #{e}"
|
raise CaskError, "Download failed on Cask '#{cask}' with message: #{e}"
|
||||||
end
|
end
|
||||||
|
@ -6,13 +6,13 @@ class URL
|
|||||||
:data
|
:data
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
attr_reader :uri
|
attr_reader :uri, :specs
|
||||||
attr_reader(*ATTRIBUTES)
|
attr_reader(*ATTRIBUTES)
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
def_delegators :uri, :path, :scheme, :to_s
|
def_delegators :uri, :path, :scheme, :to_s
|
||||||
|
|
||||||
def initialize(uri, options = {})
|
def initialize(uri, **options)
|
||||||
@uri = URI(uri)
|
@uri = URI(uri)
|
||||||
@user_agent = :default
|
@user_agent = :default
|
||||||
|
|
||||||
@ -20,5 +20,7 @@ class URL
|
|||||||
next unless options.key?(attribute)
|
next unless options.key?(attribute)
|
||||||
instance_variable_set("@#{attribute}", options[attribute])
|
instance_variable_set("@#{attribute}", options[attribute])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@specs = options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,34 +13,44 @@ describe Hbc::CLI::Fetch, :cask do
|
|||||||
it_behaves_like "a command that requires a Cask token"
|
it_behaves_like "a command that requires a Cask token"
|
||||||
it_behaves_like "a command that handles invalid options"
|
it_behaves_like "a command that handles invalid options"
|
||||||
|
|
||||||
it "allows download the installer of a Cask" do
|
it "allows downloading the installer of a Cask" do
|
||||||
|
transmission_location = CurlDownloadStrategy.new(
|
||||||
|
local_transmission.url.to_s, local_transmission.token, local_transmission.version,
|
||||||
|
cache: Hbc::Cache.path, **local_transmission.url.specs
|
||||||
|
).cached_location
|
||||||
|
caffeine_location = CurlDownloadStrategy.new(
|
||||||
|
local_caffeine.url.to_s, local_caffeine.token, local_caffeine.version,
|
||||||
|
cache: Hbc::Cache.path, **local_caffeine.url.specs
|
||||||
|
).cached_location
|
||||||
|
|
||||||
|
expect(transmission_location).not_to exist
|
||||||
|
expect(caffeine_location).not_to exist
|
||||||
|
|
||||||
described_class.run("local-transmission", "local-caffeine")
|
described_class.run("local-transmission", "local-caffeine")
|
||||||
expect(Hbc::CurlDownloadStrategy.new(local_transmission).cached_location).to exist
|
|
||||||
expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist
|
expect(transmission_location).to exist
|
||||||
|
expect(caffeine_location).to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prevents double fetch (without nuking existing installation)" do
|
it "prevents double fetch (without nuking existing installation)" do
|
||||||
download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission)
|
cached_location = Hbc::Download.new(local_transmission).perform
|
||||||
|
|
||||||
Hbc::Download.new(local_transmission).perform
|
old_ctime = File.stat(cached_location).ctime
|
||||||
old_ctime = File.stat(download_stategy.cached_location).ctime
|
|
||||||
|
|
||||||
described_class.run("local-transmission")
|
described_class.run("local-transmission")
|
||||||
new_ctime = File.stat(download_stategy.cached_location).ctime
|
new_ctime = File.stat(cached_location).ctime
|
||||||
|
|
||||||
expect(old_ctime.to_i).to eq(new_ctime.to_i)
|
expect(old_ctime.to_i).to eq(new_ctime.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows double fetch with --force" do
|
it "allows double fetch with --force" do
|
||||||
Hbc::Download.new(local_transmission).perform
|
cached_location = Hbc::Download.new(local_transmission).perform
|
||||||
|
|
||||||
download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission)
|
old_ctime = File.stat(cached_location).ctime
|
||||||
old_ctime = File.stat(download_stategy.cached_location).ctime
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
described_class.run("local-transmission", "--force")
|
described_class.run("local-transmission", "--force")
|
||||||
download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission)
|
new_ctime = File.stat(cached_location).ctime
|
||||||
new_ctime = File.stat(download_stategy.cached_location).ctime
|
|
||||||
|
|
||||||
expect(new_ctime.to_i).to be > old_ctime.to_i
|
expect(new_ctime.to_i).to be > old_ctime.to_i
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user