Commit eee0d344 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Downloader] Actually allow skipping the cache entirely

parent 5f065df1
...@@ -41,6 +41,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -41,6 +41,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
avoids an incomplete module map warning. avoids an incomplete module map warning.
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
* Actually allow skipping the download cache by downloading directly to the
download target when requested.
[Samuel Giddins](https://github.com/segiddins)
## 0.37.0 ## 0.37.0
......
...@@ -27,22 +27,97 @@ module Pod ...@@ -27,22 +27,97 @@ module Pod
def self.download( def self.download(
request, request,
target, target,
cache_path: !Config.instance.skip_download_cache && Config.instance.cache_root + 'Pods' cache_path: !Config.instance.skip_download_cache && Config.instance.clean? && Config.instance.cache_root + 'Pods'
) )
cache_path, tmp_cache = Pathname(Dir.mktmpdir), true unless cache_path if cache_path
cache = Cache.new(cache_path) cache = Cache.new(cache_path)
result = cache.download_pod(request) result = cache.download_pod(request)
if target && result.location else
result, _ = download_request(request, target)
end
if target && result.location && target != result.location
UI.message "Copying #{request.name} from `#{result.location}` to #{UI.path target}", '> ' do UI.message "Copying #{request.name} from `#{result.location}` to #{UI.path target}", '> ' do
FileUtils.rm_rf target FileUtils.rm_rf target
FileUtils.cp_r(result.location, target) FileUtils.cp_r(result.location, target)
end end
end end
result result
ensure
FileUtils.rm_r cache_path if tmp_cache
end end
# Performs the download from the given `request` to the given `target` location.
#
# @return [Response, Hash<String,Specification>]
# The download response for this download, and the specifications
# for this download grouped by name.
#
# @param [Request] request
# the request that describes this pod download.
#
# @param [Pathname,Nil] target
# the location to which this pod should be downloaded. If `nil`,
# then the pod will only be cached.
#
def self.download_request(request, target)
result = Response.new
result.checkout_options = download_source(request.name, target, request.params, request.head?)
result.location = target
if request.released_pod?
result.spec = request.spec
podspecs = { request.name => request.spec }
else
podspecs = Sandbox::PodspecFinder.new(target).podspecs
podspecs[request.name] = request.spec if request.spec
podspecs.each do |name, spec|
if request.name == name
result.spec = spec
end
end
end
[result, podspecs]
end
private
# Downloads a pod with the given `name` and `params` to `target`.
#
# @param [String] name
#
# @param [Pathname] target
#
# @param [Hash<Symbol,String>] params
#
# @param [Boolean] head
#
# @return [Hash] The checkout options required to re-download this exact
# same source.
#
def self.download_source(name, target, params, head)
FileUtils.rm_rf(target)
downloader = Downloader.for_target(target, params)
if head
unless downloader.head_supported?
raise Informative, "The pod '#{name}' does not " \
"support the :head option, as it uses a #{downloader.name} " \
'source. Remove that option to use this pod.'
end
downloader.download_head
else
downloader.download
end
target.mkpath
if downloader.options_specific? && !head
params
else
downloader.checkout_options
end
end
public
class DownloaderError; include CLAide::InformativeError; end class DownloaderError; include CLAide::InformativeError; end
class Base class Base
......
...@@ -99,25 +99,14 @@ module Pod ...@@ -99,25 +99,14 @@ module Pod
# #
def uncached_pod(request) def uncached_pod(request)
in_tmpdir do |target| in_tmpdir do |target|
result = Response.new result, podspecs = download(request, target)
result.checkout_options = download(request.name, target, request.params, request.head?)
if request.released_pod?
result.spec = request.spec
result.location = destination = path_for_pod(request, :params => result.checkout_options)
copy_and_clean(target, destination, request.spec)
write_spec(request.spec, path_for_spec(request, :params => result.checkout_options))
else
podspecs = Sandbox::PodspecFinder.new(target).podspecs
podspecs[request.name] = request.spec if request.spec
podspecs.each do |name, spec| podspecs.each do |name, spec|
destination = path_for_pod(request, :name => name, :params => result.checkout_options) destination = path_for_pod(request, :name => name, :params => result.checkout_options)
copy_and_clean(target, destination, spec) copy_and_clean(target, destination, spec)
write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options)) write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options))
if request.name == name if request.name == name
result.location = destination result.location = destination
result.spec = spec
end
end end
end end
...@@ -125,37 +114,8 @@ module Pod ...@@ -125,37 +114,8 @@ module Pod
end end
end end
# Downloads a pod with the given `name` and `params` to `target`. def download(request, target)
# Downloader.download_request(request, target)
# @param [String] name
#
# @param [Pathname] target
#
# @param [Hash<Symbol,String>] params
#
# @param [Boolean] head
#
# @return [Hash] The checkout options required to re-download this exact
# same source.
#
def download(name, target, params, head)
downloader = Downloader.for_target(target, params)
if head
unless downloader.head_supported?
raise Informative, "The pod '#{name}' does not " \
"support the :head option, as it uses a #{downloader.name} " \
'source. Remove that option to use this pod.'
end
downloader.download_head
else
downloader.download
end
if downloader.options_specific? && !head
params
else
downloader.checkout_options
end
end end
# Performs the given block inside a temporary directory, # Performs the given block inside a temporary directory,
......
...@@ -8,10 +8,16 @@ module Pod ...@@ -8,10 +8,16 @@ module Pod
@spec.source = { :git => SpecHelper.fixture('banana-lib') } @spec.source = { :git => SpecHelper.fixture('banana-lib') }
@request = Downloader::Request.new(:spec => @spec, :released => true) @request = Downloader::Request.new(:spec => @spec, :released => true)
@unreleased_request = Downloader::Request.new(:name => 'BananaLib', :params => @spec.source) @unreleased_request = Downloader::Request.new(:name => 'BananaLib', :params => @spec.source)
@stub_download = lambda do |cache, &blk|
cache.define_singleton_method(:download) do |_name, target, _params, _head| @stub_download = lambda do |&blk|
original_download_source = Downloader.method(:download_source)
Downloader.define_singleton_method(:download_source) do |_name, target, _params, _head|
FileUtils.mkdir_p target FileUtils.mkdir_p target
Dir.chdir(target) { blk.call } Dir.chdir(target) do
result = blk.call
Downloader.define_singleton_method(:download_source, original_download_source)
result
end
end end
end end
end end
...@@ -53,7 +59,7 @@ module Pod ...@@ -53,7 +59,7 @@ module Pod
describe 'when downloading an un-released pod' do describe 'when downloading an un-released pod' do
before do before do
@stub_download.call @cache do @stub_download.call do
File.open('BananaLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json } File.open('BananaLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json }
File.open('OrangeLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json.sub(/"name": "BananaLib"/, '"name": "OrangeLib"') } File.open('OrangeLib.podspec.json', 'w') { |f| f << @spec.to_pretty_json.sub(/"name": "BananaLib"/, '"name": "OrangeLib"') }
@spec.source @spec.source
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment