Commit 6588e6a5 authored by Florian Krupicka's avatar Florian Krupicka

Add explicit flattening option to Downloader:Http

With the change in 0.16.3, which disabled flattening for zip files
some pods seem to break. While the rationale for the flattening
change is a good one, it would be nice to reenable flattening support
explicitly in the source configuration for your pod.

references https://github.com/CocoaPods/CocoaPods/issues/812
parent 0e40a6c1
...@@ -26,6 +26,16 @@ module Pod ...@@ -26,6 +26,16 @@ module Pod
options[:type] || type_with_url(url) options[:type] || type_with_url(url)
end end
def should_flatten?
if options.has_key? :flatten
options[:flatten] # spec file can always override
elsif [:tgz, :tar, :tbz].include? type
true # those archives flatten by default
else
false # all others (actually only .zip) default not to flatten
end
end
private private
def type_with_url(url) def type_with_url(url)
if url =~ /.zip$/ if url =~ /.zip$/
...@@ -74,8 +84,7 @@ module Pod ...@@ -74,8 +84,7 @@ module Pod
raise UnsupportedFileTypeError.new "Unsupported file type: #{type}" raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end end
# If the archive is a tarball and it only contained a folder, move its contents to the target (#727) if should_flatten?
if [:tgz, :tar, :tbz].include? type
contents = target_path.children contents = target_path.children
contents.delete(full_filename) contents.delete(full_filename)
entry = contents.first entry = contents.first
......
...@@ -101,4 +101,15 @@ describe Pod::Downloader::Http do ...@@ -101,4 +101,15 @@ describe Pod::Downloader::Http do
# Archive contains 4 files, and the archive is 1 # Archive contains 4 files, and the archive is 1
Dir.glob(downloader.target_path + '*').count.should == 4 + 1 Dir.glob(downloader.target_path + '*').count.should == 4 + 1
end end
it 'should flatten zip archives, when the spec explicitly demands it' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://github.com/kevinoneill/Useful-Bits/archive/1.0.zip',
:flatten => true
))
downloader.download
# Archive contains one folder, which contains 8 items. The archive is 1, and the
# parent folder that we moved stuff out of is 1.
Dir.glob(downloader.target_path + '*').count.should == 8 + 1 + 1
end
end end
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