Skip to content

Commit

Permalink
Add support for packages containing a single archive file (#3)
Browse files Browse the repository at this point in the history
* Bump version

* Extract archives if the package contains a single file
  • Loading branch information
Frugghi authored Jan 8, 2021
1 parent 24b051b commit 9566386
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
cocoapods-azure-universal-packages (0.0.1)
cocoapods-azure-universal-packages (0.0.2)
addressable (~> 2.6)
cocoapods (~> 1.0)
cocoapods-downloader (~> 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ def download!

if !aup_uri_components.nil? && Downloader.azure_base_urls.include?("#{aup_uri_components['scheme']}://#{aup_uri_components['host']}")
download_azure_universal_package!(aup_uri_components)

# Extract the file if it's the only one in the package
package_files = target_path.glob('*')
if package_files.count == 1 && package_files.first.file?
file = package_files.first
file_type = begin
case file.to_s
when /\.zip$/
:zip
when /\.(tgz|tar\.gz)$/
:tgz
when /\.tar$/
:tar
when /\.(tbz|tar\.bz2)$/
:tbz
when /\.(txz|tar\.xz)$/
:txz
when /\.dmg$/
:dmg
end
end
extract_with_type(file, file_type) unless file_type.nil?
end
else
aliased_download!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-azure-universal-packages/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CocoapodsAzureUniversalPackages
VERSION = "0.0.1"
VERSION = "0.0.2"
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
downloader = Pod::Downloader::Http.new("/tmp", "https://www.microsoft.com", {})

downloader.target_path.stubs(:mkpath)
downloader.target_path.stubs(:glob).returns([])
downloader.expects(:aliased_download!)
downloader.download
end
Expand All @@ -33,6 +34,7 @@
]

downloader.target_path.stubs(:mkpath)
downloader.target_path.stubs(:glob).returns([])
downloader.expects(:execute_command).with('az', parameters, anything)
downloader.download
end
Expand All @@ -53,11 +55,59 @@
]

downloader.target_path.stubs(:mkpath)
downloader.target_path.stubs(:glob).returns([])
downloader.expects(:execute_command).with('az', parameters, anything)
downloader.download
end
end

context 'when downloading a universal package with a single file' do

[
[:zip, '.zip'],
[:tgz, '.tgz'], [:tgz, '.tar.gz'],
[:tar, '.tar'],
[:tbz, '.tbz'], [:tbz, '.tar.bz2'],
[:txz, '.txz'], [:txz, '.tar.xz'],
[:dmg, '.dmg'],
].each do |params|
it 'extracts the archive ' + params[1] do
downloader = Pod::Downloader::Http.new("/tmp", "https://pkgs.dev.azure.com/test_org/test_project/_apis/packaging/feeds/project_feed/upack/packages/test_package/versions/1.2.3", {})
archive = Pathname("/tmp/archive#{params[1]}")
archive_type = params[0]

archive.stubs(:file?).returns(true)
downloader.target_path.stubs(:mkpath)
downloader.target_path.stubs(:glob).returns([archive])
downloader.expects(:extract_with_type).with(archive, archive_type)
downloader.download
end
end

it 'does not extract non archive files' do
downloader = Pod::Downloader::Http.new("/tmp", "https://pkgs.dev.azure.com/test_org/test_project/_apis/packaging/feeds/project_feed/upack/packages/test_package/versions/1.2.3", {})
file = Pathname("/tmp/file.txt")

file.stubs(:file?).returns(true)
downloader.target_path.stubs(:mkpath)
downloader.target_path.stubs(:glob).returns([file])
downloader.expects(:extract_with_type).never
downloader.download
end

it 'does not extract directories' do
downloader = Pod::Downloader::Http.new("/tmp", "https://pkgs.dev.azure.com/test_org/test_project/_apis/packaging/feeds/project_feed/upack/packages/test_package/versions/1.2.3", {})
dir = Pathname("/tmp/dir.zip")

dir.stubs(:file?).returns(false)
downloader.target_path.stubs(:mkpath)
downloader.target_path.stubs(:glob).returns([dir])
downloader.expects(:extract_with_type).never
downloader.download
end

end

end

end

0 comments on commit 9566386

Please sign in to comment.