cocoapods-downloader 1.1.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cocoapods-downloader might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 39f931857e0e88b2b1bfbd27f1444194e1f0964f
4
- data.tar.gz: 04825acb584a9417a5dae4fa01a328e4233b5e82
2
+ SHA256:
3
+ metadata.gz: 128f7eaefbd34c1b7f9c66c06a45dd5e3d186322938a8346fc5283df450617d0
4
+ data.tar.gz: 60a084074452df93b41cfda6248c2fc455b8111c109fc471075e96ca7085e5b9
5
5
  SHA512:
6
- metadata.gz: 8fbd2e3973f247c1a86243b1c5ab2bf00717cc928f55c8c71f5465001f1120c88c3e81bd7316847c3e7acb8fd15df300890408b9b60eaabdb615ae3cccd3584c
7
- data.tar.gz: b5aadb492243642b60dece83d37a16968aaf997af47f94b1d56af92bc0bb091d1b2243aabf6ac1746b3b0866f56af232572c05b9f2ce08f661a520642e2175f2
6
+ metadata.gz: 2fd8b780dc60807be9317865fea329ecf608f18ce1e81bca8653c23b548589d9b7c3099d4e82ff7c7097e75f256e856ff788d2691f34312798e61f13f13154f3
7
+ data.tar.gz: 8435a98df7285ea8753b443656e306d1467dc8bfa28551c70d018630c03ad8820dc564576bd70a90d51d848cdad184a8e8b00ab59d05950740af4548d0971ae0
@@ -33,6 +33,7 @@ The downloader class supports the following option keys:
33
33
  - svn: revision, tag, folder, externals
34
34
  - hg: revision, tag, branch
35
35
  - http: type, flatten
36
+ - scp: type, flatten
36
37
  - bzr: revision, tag
37
38
 
38
39
  The downloader also provides hooks which allow to customize its output or the way in which the commands are executed
@@ -9,6 +9,7 @@ module Pod
9
9
  autoload :Git, 'cocoapods-downloader/git'
10
10
  autoload :Http, 'cocoapods-downloader/http'
11
11
  autoload :Mercurial, 'cocoapods-downloader/mercurial'
12
+ autoload :Scp, 'cocoapods-downloader/scp'
12
13
  autoload :Subversion, 'cocoapods-downloader/subversion'
13
14
 
14
15
  # Denotes the error generated by a Downloader
@@ -24,6 +25,7 @@ module Pod
24
25
  :git => Git,
25
26
  :hg => Mercurial,
26
27
  :http => Http,
28
+ :scp => Scp,
27
29
  :svn => Subversion,
28
30
  }
29
31
  end
@@ -121,6 +121,18 @@ module Pod
121
121
  raise 'Abstract method'
122
122
  end
123
123
 
124
+ # Returns a User-Agent string that itentifies http network requests as
125
+ # originating from CocoaPods.
126
+ # Contains version numbers from the CocoaPods Gem and the cocoapods-downloader Gem.
127
+ #
128
+ # @param [module] base_module The Base CocoaPods Module to retrieve the version number from.
129
+ # @return [String] the User-Agent string.
130
+ #
131
+ def self.user_agent_string(base_module = Pod)
132
+ pods_version = base_module.const_defined?('VERSION') ? "CocoaPods/#{base_module::VERSION} " : ''
133
+ "#{pods_version}cocoapods-downloader/#{Pod::Downloader::VERSION}"
134
+ end
135
+
124
136
  #-----------------------------------------------------------------------#
125
137
 
126
138
  # Defines two methods for an executable, based on its name. The bang
@@ -3,6 +3,6 @@ module Pod
3
3
  # @return [String] Downloader’s version, following
4
4
  # [semver](http://semver.org).
5
5
  #
6
- VERSION = '1.1.3'.freeze
6
+ VERSION = '1.4.0'.freeze
7
7
  end
8
8
  end
@@ -27,16 +27,37 @@ module Pod
27
27
  options[:git],
28
28
  options[:branch]]
29
29
  output = Git.execute_command('git', command)
30
- match = /^([a-z0-9]*)\t.*/.match(output)
30
+ match = commit_from_ls_remote output, options[:branch]
31
31
 
32
32
  return options if match.nil?
33
33
 
34
- options[:commit] = match[1]
34
+ options[:commit] = match
35
35
  options.delete(:branch)
36
36
 
37
37
  options
38
38
  end
39
39
 
40
+ # Matches a commit from the branches reported by git ls-remote.
41
+ #
42
+ # @note When there is a branch and tag with the same name, it will match
43
+ # the branch, since `refs/heads` is sorted before `refs/tags`.
44
+ #
45
+ # @param [String] output
46
+ # The output from git ls-remote.
47
+ #
48
+ # @param [String] branch_name
49
+ # The desired branch to match a commit to.
50
+ #
51
+ # @return [String] commit hash string, or nil if no match found
52
+ #
53
+ def self.commit_from_ls_remote(output, branch_name)
54
+ return nil if branch_name.nil?
55
+ match = %r{([a-z0-9]*)\trefs\/(heads|tags)\/#{Regexp.quote(branch_name)}}.match(output)
56
+ match[1] unless match.nil?
57
+ end
58
+
59
+ private_class_method :commit_from_ls_remote
60
+
40
61
  private
41
62
 
42
63
  # @!group Base class hooks
@@ -1,179 +1,33 @@
1
- require 'zlib'
2
- require 'fileutils'
3
- require 'uri'
1
+ require 'cocoapods-downloader/remote_file'
4
2
 
5
3
  module Pod
6
4
  module Downloader
7
- class Http < Base
8
- def self.options
9
- [:type, :flatten, :sha1, :sha256]
10
- end
11
-
12
- class UnsupportedFileTypeError < StandardError; end
5
+ class Http < RemoteFile
6
+ USER_AGENT_HEADER = 'User-Agent'.freeze
13
7
 
14
8
  private
15
9
 
16
10
  executable :curl
17
- executable :unzip
18
- executable :tar
19
- executable :hdiutil
20
-
21
- attr_accessor :filename, :download_path
22
-
23
- def download!
24
- @filename = filename_with_type(type)
25
- @download_path = (target_path + @filename)
26
- download_file(@download_path)
27
- verify_checksum(@download_path)
28
- extract_with_type(@download_path, type)
29
- end
30
-
31
- def type
32
- if options[:type]
33
- options[:type].to_sym
34
- else
35
- type_with_url(url)
36
- end
37
- end
38
-
39
- # @note The archive is flattened if it contains only one folder and its
40
- # extension is either `tgz`, `tar`, `tbz` or the options specify
41
- # it.
42
- #
43
- # @return [Bool] Whether the archive should be flattened if it contains
44
- # only one folder.
45
- #
46
- def should_flatten?
47
- if options.key?(:flatten)
48
- true
49
- elsif [:tgz, :tar, :tbz, :txz].include?(type)
50
- true # those archives flatten by default
51
- else
52
- false # all others (actually only .zip) default not to flatten
53
- end
54
- end
55
-
56
- def type_with_url(url)
57
- case URI.parse(url).path
58
- when /\.zip$/
59
- :zip
60
- when /\.(tgz|tar\.gz)$/
61
- :tgz
62
- when /\.tar$/
63
- :tar
64
- when /\.(tbz|tar\.bz2)$/
65
- :tbz
66
- when /\.(txz|tar\.xz)$/
67
- :txz
68
- when /\.dmg$/
69
- :dmg
70
- end
71
- end
72
-
73
- def filename_with_type(type = :zip)
74
- case type
75
- when :zip
76
- 'file.zip'
77
- when :tgz
78
- 'file.tgz'
79
- when :tar
80
- 'file.tar'
81
- when :tbz
82
- 'file.tbz'
83
- when :txz
84
- 'file.txz'
85
- when :dmg
86
- 'file.dmg'
87
- else
88
- raise UnsupportedFileTypeError, "Unsupported file type: #{type}"
89
- end
90
- end
91
11
 
92
12
  def download_file(full_filename)
93
- curl! '-f', '-L', '-o', full_filename, url, '--create-dirs', '--netrc-optional'
94
- end
95
-
96
- def extract_with_type(full_filename, type = :zip)
97
- unpack_from = full_filename
98
- unpack_to = @target_path
99
- case type
100
- when :zip
101
- unzip! unpack_from, '-d', unpack_to
102
- when :tgz
103
- tar! 'xfz', unpack_from, '-C', unpack_to
104
- when :tar
105
- tar! 'xf', unpack_from, '-C', unpack_to
106
- when :tbz
107
- tar! 'xfj', unpack_from, '-C', unpack_to
108
- when :txz
109
- tar! 'xf', unpack_from, '-C', unpack_to
110
- when :dmg
111
- extract_dmg(unpack_from, unpack_to)
112
- else
113
- raise UnsupportedFileTypeError, "Unsupported file type: #{type}"
114
- end
115
-
116
- # If the archive is a tarball and it only contained a folder, move its
117
- # contents to the target (#727)
118
- #
119
- if should_flatten?
120
- contents = @target_path.children
121
- contents.delete(target_path + @filename)
122
- entry = contents.first
123
- if contents.count == 1 && entry.directory?
124
- FileUtils.move(entry.children, target_path)
125
- end
126
- end
127
- end
128
-
129
- def extract_dmg(unpack_from, unpack_to)
130
- require 'rexml/document'
131
- plist_s = hdiutil! 'attach', '-plist', '-nobrowse', unpack_from, '-mountrandom', unpack_to
132
- plist = REXML::Document.new plist_s
133
- xpath = '//key[.="mount-point"]/following-sibling::string'
134
- mount_point = REXML::XPath.first(plist, xpath).text
135
- FileUtils.cp_r(Dir.glob(mount_point + '/*'), unpack_to)
136
- hdiutil! 'detach', mount_point
137
- end
13
+ parameters = ['-f', '-L', '-o', full_filename, url, '--create-dirs', '--netrc-optional', '--retry', '2']
14
+ parameters << user_agent_argument if headers.nil? ||
15
+ headers.none? { |header| header.casecmp(USER_AGENT_HEADER).zero? }
138
16
 
139
- def compare_hash(filename, hasher, hash)
140
- incremental_hash = hasher.new
17
+ headers.each do |h|
18
+ parameters << '-H'
19
+ parameters << h
20
+ end unless headers.nil?
141
21
 
142
- File.open(filename, 'rb') do |file|
143
- buf = ''
144
- incremental_hash << buf while file.read(1024, buf)
145
- end
146
-
147
- computed_hash = incremental_hash.hexdigest
148
-
149
- if computed_hash != hash
150
- raise DownloaderError, 'Verification checksum was incorrect, ' \
151
- "expected #{hash}, got #{computed_hash}"
152
- end
22
+ curl! parameters
153
23
  end
154
24
 
155
- # Verify that the downloaded file matches a sha1 hash
25
+ # Returns a cURL command flag to add the CocoaPods User-Agent.
156
26
  #
157
- def verify_sha1_hash(filename, hash)
158
- require 'digest/sha1'
159
- compare_hash(filename, Digest::SHA1, hash)
160
- end
161
-
162
- # Verify that the downloaded file matches a sha256 hash
163
- #
164
- def verify_sha256_hash(filename, hash)
165
- require 'digest/sha2'
166
- compare_hash(filename, Digest::SHA2, hash)
167
- end
168
-
169
- # Verify that the downloaded file matches the hash if set
27
+ # @return [String] cURL command -A flag and User-Agent.
170
28
  #
171
- def verify_checksum(filename)
172
- if options[:sha256]
173
- verify_sha256_hash(filename, options[:sha256])
174
- elsif options[:sha1]
175
- verify_sha1_hash(filename, options[:sha1])
176
- end
29
+ def user_agent_argument
30
+ "-A '#{Http.user_agent_string}'"
177
31
  end
178
32
  end
179
33
  end
@@ -0,0 +1,182 @@
1
+ require 'fileutils'
2
+ require 'uri'
3
+ require 'zlib'
4
+
5
+ module Pod
6
+ module Downloader
7
+ class RemoteFile < Base
8
+ def self.options
9
+ [:type, :flatten, :sha1, :sha256, :headers]
10
+ end
11
+
12
+ class UnsupportedFileTypeError < StandardError; end
13
+
14
+ private
15
+
16
+ executable :unzip
17
+ executable :tar
18
+ executable :hdiutil
19
+
20
+ attr_accessor :filename, :download_path
21
+
22
+ def download!
23
+ @filename = filename_with_type(type)
24
+ @download_path = target_path + @filename
25
+ download_file(@download_path)
26
+ verify_checksum(@download_path)
27
+ extract_with_type(@download_path, type)
28
+ end
29
+
30
+ def type
31
+ if options[:type]
32
+ options[:type].to_sym
33
+ else
34
+ type_with_url(url)
35
+ end
36
+ end
37
+
38
+ def headers
39
+ options[:headers]
40
+ end
41
+
42
+ # @note The archive is flattened if it contains only one folder and its
43
+ # extension is either `tgz`, `tar`, `tbz` or the options specify
44
+ # it.
45
+ #
46
+ # @return [Bool] Whether the archive should be flattened if it contains
47
+ # only one folder.
48
+ #
49
+ def should_flatten?
50
+ if options.key?(:flatten)
51
+ options[:flatten]
52
+ elsif [:tgz, :tar, :tbz, :txz].include?(type)
53
+ true # those archives flatten by default
54
+ else
55
+ false # all others (actually only .zip) default not to flatten
56
+ end
57
+ end
58
+
59
+ def type_with_url(url)
60
+ case URI.parse(url).path
61
+ when /\.zip$/
62
+ :zip
63
+ when /\.(tgz|tar\.gz)$/
64
+ :tgz
65
+ when /\.tar$/
66
+ :tar
67
+ when /\.(tbz|tar\.bz2)$/
68
+ :tbz
69
+ when /\.(txz|tar\.xz)$/
70
+ :txz
71
+ when /\.dmg$/
72
+ :dmg
73
+ end
74
+ end
75
+
76
+ def filename_with_type(type = :zip)
77
+ case type
78
+ when :zip, :tgz, :tar, :tbz, :txz, :dmg
79
+ "file.#{type}"
80
+ else
81
+ raise UnsupportedFileTypeError, "Unsupported file type: #{type}"
82
+ end
83
+ end
84
+
85
+ def download_file(_full_filename)
86
+ raise NotImplementedError
87
+ end
88
+
89
+ def extract_with_type(full_filename, type = :zip)
90
+ unpack_from = full_filename
91
+ unpack_to = @target_path
92
+
93
+ case type
94
+ when :zip
95
+ unzip! unpack_from, '-d', unpack_to
96
+ when :tgz
97
+ tar! 'xfz', unpack_from, '-C', unpack_to
98
+ when :tar
99
+ tar! 'xf', unpack_from, '-C', unpack_to
100
+ when :tbz
101
+ tar! 'xfj', unpack_from, '-C', unpack_to
102
+ when :txz
103
+ tar! 'xf', unpack_from, '-C', unpack_to
104
+ when :dmg
105
+ extract_dmg(unpack_from, unpack_to)
106
+ else
107
+ raise UnsupportedFileTypeError, "Unsupported file type: #{type}"
108
+ end
109
+
110
+ # If the archive is a tarball and it only contained a folder, move its
111
+ # contents to the target (#727)
112
+ #
113
+ if should_flatten?
114
+ contents = target_path.children
115
+ contents.delete(target_path + @filename)
116
+ entry = contents.first
117
+ if contents.count == 1 && entry.directory?
118
+ tmp_entry = entry.sub_ext("#{entry.extname}.tmp")
119
+ begin
120
+ FileUtils.move(entry, tmp_entry)
121
+ FileUtils.move(tmp_entry.children, target_path)
122
+ ensure
123
+ FileUtils.remove_entry(tmp_entry)
124
+ end
125
+ end
126
+ end
127
+
128
+ FileUtils.rm(unpack_from) if File.exist?(unpack_from)
129
+ end
130
+
131
+ def extract_dmg(unpack_from, unpack_to)
132
+ require 'rexml/document'
133
+ plist_s = hdiutil! 'attach', '-plist', '-nobrowse', unpack_from, '-mountrandom', unpack_to
134
+ plist = REXML::Document.new plist_s
135
+ xpath = '//key[.="mount-point"]/following-sibling::string'
136
+ mount_point = REXML::XPath.first(plist, xpath).text
137
+ FileUtils.cp_r(Dir.glob(mount_point + '/*'), unpack_to)
138
+ hdiutil! 'detach', mount_point
139
+ end
140
+
141
+ def compare_hash(filename, hasher, hash)
142
+ incremental_hash = hasher.new
143
+
144
+ File.open(filename, 'rb') do |file|
145
+ buf = ''
146
+ incremental_hash << buf while file.read(1024, buf)
147
+ end
148
+
149
+ computed_hash = incremental_hash.hexdigest
150
+
151
+ if computed_hash != hash
152
+ raise DownloaderError, 'Verification checksum was incorrect, ' \
153
+ "expected #{hash}, got #{computed_hash}"
154
+ end
155
+ end
156
+
157
+ # Verify that the downloaded file matches a sha1 hash
158
+ #
159
+ def verify_sha1_hash(filename, hash)
160
+ require 'digest/sha1'
161
+ compare_hash(filename, Digest::SHA1, hash)
162
+ end
163
+
164
+ # Verify that the downloaded file matches a sha256 hash
165
+ #
166
+ def verify_sha256_hash(filename, hash)
167
+ require 'digest/sha2'
168
+ compare_hash(filename, Digest::SHA2, hash)
169
+ end
170
+
171
+ # Verify that the downloaded file matches the hash if set
172
+ #
173
+ def verify_checksum(filename)
174
+ if options[:sha256]
175
+ verify_sha256_hash(filename, options[:sha256])
176
+ elsif options[:sha1]
177
+ verify_sha1_hash(filename, options[:sha1])
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,30 @@
1
+ require 'uri'
2
+ require 'cocoapods-downloader/remote_file'
3
+
4
+ module Pod
5
+ module Downloader
6
+ class Scp < RemoteFile
7
+ DEFAULT_PORT = 22
8
+
9
+ private
10
+
11
+ executable :scp
12
+
13
+ def download_file(full_filename)
14
+ scp! '-P', port, '-q', source, full_filename
15
+ end
16
+
17
+ def source
18
+ "#{uri.user ? uri.user + '@' : ''}#{uri.host}:'#{uri.path}'"
19
+ end
20
+
21
+ def port
22
+ uri.port || DEFAULT_PORT
23
+ end
24
+
25
+ def uri
26
+ @uri ||= URI.parse(url)
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Duran
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-17 00:00:00.000000000 Z
12
+ date: 2020-07-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -30,8 +30,10 @@ files:
30
30
  - lib/cocoapods-downloader/git.rb
31
31
  - lib/cocoapods-downloader/http.rb
32
32
  - lib/cocoapods-downloader/mercurial.rb
33
+ - lib/cocoapods-downloader/remote_file.rb
34
+ - lib/cocoapods-downloader/scp.rb
33
35
  - lib/cocoapods-downloader/subversion.rb
34
- homepage: https://github.com/CocoaPods/Downloader
36
+ homepage: https://github.com/CocoaPods/cocoapods-downloader
35
37
  licenses:
36
38
  - MIT
37
39
  metadata: {}
@@ -43,15 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
45
  requirements:
44
46
  - - ">="
45
47
  - !ruby/object:Gem::Version
46
- version: 2.0.0
48
+ version: 2.3.3
47
49
  required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  requirements:
49
51
  - - ">="
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  requirements: []
53
- rubyforge_project:
54
- rubygems_version: 2.4.5.1
55
+ rubygems_version: 3.0.3
55
56
  signing_key:
56
57
  specification_version: 3
57
58
  summary: A small library for downloading files from remotes in a folder.