From 9e2a78e07888806bf85436ef4f9246c043ac0984 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Mon, 25 May 2020 15:13:56 +0300 Subject: [PATCH 1/3] add a #local_file_okay? check to help with CDN client robustness --- lib/cocoapods-core/cdn_source.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/cdn_source.rb b/lib/cocoapods-core/cdn_source.rb index 2b2598426..19f985a77 100644 --- a/lib/cocoapods-core/cdn_source.rb +++ b/lib/cocoapods-core/cdn_source.rb @@ -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| @@ -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) @@ -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) From 08b719e50cf7c71fc224e1f93d75ff2600bd8f89 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Mon, 25 May 2020 15:19:56 +0300 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 810a41031..1087082d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From c807b2ce7dd95c5175e732911778c14ad9332960 Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Mon, 25 May 2020 15:28:48 +0300 Subject: [PATCH 3/3] add test for invalid file handling --- spec/cdn_source_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/cdn_source_spec.rb b/spec/cdn_source_spec.rb index 6b0df216a..af7fe4da5 100644 --- a/spec/cdn_source_spec.rb +++ b/spec/cdn_source_spec.rb @@ -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')