Commit 3c7c2d8b authored by Marius Rackwitz's avatar Marius Rackwitz

[Cache] Ensure to verify cached specification

Even when cached_spec isn't used further with local podspecs, it still must be read from file to verify that it was correctly written before, because that also indicates that the cached pod is valid.
parent b883987d
...@@ -76,10 +76,10 @@ module Pod ...@@ -76,10 +76,10 @@ module Pod
# was found in the download cache. # was found in the download cache.
# #
def cached_pod(request) def cached_pod(request)
cached_spec = cached_spec(request)
path = path_for_pod(request) path = path_for_pod(request)
spec_path = path_for_spec(request) return unless cached_spec && path.directory?
spec = request.spec || cached_spec(request) spec = request.spec || cached_spec
return unless spec && path.directory? && spec_path.file?
Response.new(path, spec, request.params) Response.new(path, spec, request.params)
end end
...@@ -92,6 +92,8 @@ module Pod ...@@ -92,6 +92,8 @@ module Pod
def cached_spec(request) def cached_spec(request)
path = path_for_spec(request) path = path_for_spec(request)
path.file? && Specification.from_file(path) path.file? && Specification.from_file(path)
rescue JSON::ParserError
nil
end end
# @param [Request] request # @param [Request] request
......
...@@ -75,6 +75,24 @@ module Pod ...@@ -75,6 +75,24 @@ module Pod
end end
describe 'when the cache is incomplete' do describe 'when the cache is incomplete' do
shared 'it falls back to download the pod' do
describe 'when downloading a released pod' do
it 'does download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@request)
end
end
describe 'when downloading an unreleased pod' do
it 'does download the source' do
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@unreleased_request)
end
end
end
before do before do
[@request, @unreleased_request].each do |request| [@request, @unreleased_request].each do |request|
path_for_pod = @cache.send(:path_for_pod, request) path_for_pod = @cache.send(:path_for_pod, request)
...@@ -86,20 +104,20 @@ module Pod ...@@ -86,20 +104,20 @@ module Pod
end end
end end
describe 'when downloading a released pod' do describe 'because the spec is missing' do
it 'does download the source' do behaves_like 'it falls back to download the pod'
Downloader::Git.any_instance.expects(:download).never
@cache.expects(:uncached_pod).once
@cache.download_pod(@request)
end
end end
describe 'when downloading an unreleased pod' do describe 'because the spec is invalid' do
it 'does download the source' do before do
Downloader::Git.any_instance.expects(:download).never [@request, @unreleased_request].each do |request|
@cache.expects(:uncached_pod).once path_for_spec = @cache.send(:path_for_spec, request)
@cache.download_pod(@unreleased_request) path_for_spec.dirname.mkpath
path_for_spec.open('w') { |f| f << '{' }
end
end end
behaves_like 'it falls back to download the pod'
end end
end end
......
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