Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDNSource - Run a rudimentary local check to help with CDN client robustness #632

Merged
merged 3 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

##### Bug Fixes

* None.

* CDNSource - Run a rudimentary local check to help with CDN client robustness.
[Igor Makarov](https://github.com/igor-makarov)
[#632](https://github.com/CocoaPods/Core/pull/632)
[CocoaPods#9814](https://github.com/CocoaPods/CocoaPods/issues/9814)

## 1.9.2 (2020-05-22)

Expand Down
10 changes: 8 additions & 2 deletions lib/cocoapods-core/cdn_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def pod_shard_fragment(pod_name)
metadata.path_fragment(pod_name)[0..-2]
end

def local_file_okay?(partial_url)
file_path = repo.join(partial_url)
File.exist?(file_path) && File.size(file_path) > 0
end

def local_file(partial_url)
file_path = repo.join(partial_url)
File.open(file_path) do |file|
Expand All @@ -337,7 +342,8 @@ def download_file_async(partial_url)
file_remote_url = URI.encode(url + partial_url.to_s)
path = repo + partial_url

if File.exist?(path)
file_okay = local_file_okay?(partial_url)
if file_okay
if @startup_time < File.mtime(path)
debug "CDN: #{name} Relative path: #{partial_url} modified during this run! Returning local"
return Promises.fulfilled_future(partial_url, HYDRA_EXECUTOR)
Expand All @@ -353,7 +359,7 @@ def download_file_async(partial_url)

etag_path = path.sub_ext(path.extname + '.etag')

etag = File.read(etag_path) if File.exist?(etag_path)
etag = File.read(etag_path) if file_okay && File.exist?(etag_path)
debug "CDN: #{name} Relative path: #{partial_url}, has ETag? #{etag}" unless etag.nil?

download_and_save_with_retries_async(partial_url, file_remote_url, etag)
Expand Down
9 changes: 9 additions & 0 deletions spec/cdn_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ def typhoeus_non_http_response_future(code)
spec.version.should.to_s == '1.0.5'
end

it 'downloads specification again if file is not valid' do
# create empty podspec file
FileUtils.mkdir_p(@path + 'Specs/2/0/9/BeaconKit/1.0.5')
FileUtils.touch(@path + 'Specs/2/0/9/BeaconKit/1.0.5/BeaconKit.podspec.json')
spec = @source.specification('BeaconKit', Version.new('1.0.5'))
spec.name.should == 'BeaconKit'
spec.version.should.to_s == '1.0.5'
end

it 'does not attempt to access a version not in the version index' do
@source.versions('BeaconKit')

Expand Down