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

supporting file type from sonatype nexus query urls #101

Closed
wants to merge 17 commits into from
20 changes: 18 additions & 2 deletions lib/cocoapods-downloader/remote_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def self.options
[:type, :flatten, :sha1, :sha256, :headers]
end

class UnsupportedFileTypeError < StandardError; end
class UnsupportedFileTypeError < StandardError
end

private

Expand Down Expand Up @@ -57,7 +58,16 @@ def should_flatten?
end

def type_with_url(url)
case URI.parse(url).path
url_path = URI.parse(url).path
if type_from_url_path(url_path).nil?
type_with_url_query(url)
else
type_from_url_path(url_path)
end
end

def type_from_url_path(url_path)
case url_path
when /\.zip$/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this get pulled out into a separate function so the case logic isn't duplicated in type_with_url_query? maybe type_with_extension and then call that here and in type_with_url_query

:zip
when /\.(tgz|tar\.gz)$/
Expand All @@ -73,6 +83,12 @@ def type_with_url(url)
end
end

def type_with_url_query(url)
query = URI.parse(url).query.to_s
query_params = Hash[URI.decode_www_form(query)]
type_from_url_path(query_params['file_path'])
end

def filename_with_type(type = :zip)
case type
when :zip, :tgz, :tar, :tbz, :txz, :dmg
Expand Down
Binary file added spec/fixtures/remote_file/download_file
Binary file not shown.
8 changes: 8 additions & 0 deletions spec/remote_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def download_file(full_filename)
tmp_folder_with_quotes('lib/file.txt').read.strip.should =~ /This is a fixture/
end

it 'should download file and unzip it when the target url contains file_path query param' do
options = { :http => "#{@fixtures_url}/download_file?file_path=lib.zip" }
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
tmp_folder('lib/file.txt').should.exist
tmp_folder('lib/file.txt').read.strip.should =~ /This is a fixture/
end

it 'should flatten zip archives, when the spec explicitly demands it' do
options = { :flatten => true }
downloader = MockRemoteFile.new(tmp_folder, "#{@fixtures_url}/lib.zip", options)
Expand Down