Skip to content

Commit

Permalink
Merge pull request #632 from igor-makarov/fix-empty-files
Browse files Browse the repository at this point in the history
CDNSource - Run a rudimentary local check to help with CDN client robustness
  • Loading branch information
dnkoutso authored May 25, 2020
2 parents 85110a5 + c807b2c commit 52e3b59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit 52e3b59

Please sign in to comment.