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
# was found in the download cache.
#
def cached_pod(request)
cached_spec = cached_spec(request)
path = path_for_pod(request)
spec_path = path_for_spec(request)
spec = request.spec || cached_spec(request)
return unless spec && path.directory? && spec_path.file?
return unless cached_spec && path.directory?
spec = request.spec || cached_spec
Response.new(path, spec, request.params)
end
......@@ -92,6 +92,8 @@ module Pod
def cached_spec(request)
path = path_for_spec(request)
path.file? && Specification.from_file(path)
rescue JSON::ParserError
nil
end
# @param [Request] request
......
......@@ -75,17 +75,7 @@ module Pod
end
describe 'when the cache is incomplete' do
before do
[@request, @unreleased_request].each do |request|
path_for_pod = @cache.send(:path_for_pod, request)
path_for_pod.mkpath
Dir.chdir(path_for_pod) do
FileUtils.mkdir_p 'Classes'
File.open('Classes/a.m', 'w') {}
end
end
end
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
......@@ -103,6 +93,34 @@ module Pod
end
end
before do
[@request, @unreleased_request].each do |request|
path_for_pod = @cache.send(:path_for_pod, request)
path_for_pod.mkpath
Dir.chdir(path_for_pod) do
FileUtils.mkdir_p 'Classes'
File.open('Classes/a.m', 'w') {}
end
end
end
describe 'because the spec is missing' do
behaves_like 'it falls back to download the pod'
end
describe 'because the spec is invalid' do
before do
[@request, @unreleased_request].each do |request|
path_for_spec = @cache.send(:path_for_spec, request)
path_for_spec.dirname.mkpath
path_for_spec.open('w') { |f| f << '{' }
end
end
behaves_like 'it falls back to download the pod'
end
end
describe 'when the download is cached' do
before do
[@request, @unreleased_request].each do |request|
......
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