rubygems-update 1.8.30 → 2.0.0.preview2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (241) hide show
  1. checksums.yaml +6 -6
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/.autotest +6 -3
  5. data/History.txt +137 -63
  6. data/LICENSE.txt +1 -5
  7. data/Manifest.txt +69 -32
  8. data/README.rdoc +11 -9
  9. data/Rakefile +24 -38
  10. data/bin/gem +0 -9
  11. data/bin/update_rubygems +1 -0
  12. data/lib/rubygems.rb +193 -405
  13. data/lib/rubygems/available_set.rb +95 -0
  14. data/lib/rubygems/command.rb +88 -45
  15. data/lib/rubygems/command_manager.rb +67 -40
  16. data/lib/rubygems/commands/build_command.rb +5 -23
  17. data/lib/rubygems/commands/cert_command.rb +199 -57
  18. data/lib/rubygems/commands/check_command.rb +14 -39
  19. data/lib/rubygems/commands/cleanup_command.rb +9 -1
  20. data/lib/rubygems/commands/contents_command.rb +30 -12
  21. data/lib/rubygems/commands/dependency_command.rb +3 -8
  22. data/lib/rubygems/commands/environment_command.rb +13 -8
  23. data/lib/rubygems/commands/fetch_command.rb +3 -16
  24. data/lib/rubygems/commands/generate_index_command.rb +7 -47
  25. data/lib/rubygems/commands/help_command.rb +1 -1
  26. data/lib/rubygems/commands/install_command.rb +69 -36
  27. data/lib/rubygems/commands/list_command.rb +6 -4
  28. data/lib/rubygems/commands/lock_command.rb +1 -1
  29. data/lib/rubygems/commands/mirror_command.rb +17 -0
  30. data/lib/rubygems/commands/outdated_command.rb +6 -3
  31. data/lib/rubygems/commands/owner_command.rb +13 -5
  32. data/lib/rubygems/commands/pristine_command.rb +19 -4
  33. data/lib/rubygems/commands/push_command.rb +12 -1
  34. data/lib/rubygems/commands/query_command.rb +43 -27
  35. data/lib/rubygems/commands/rdoc_command.rb +23 -28
  36. data/lib/rubygems/commands/search_command.rb +4 -18
  37. data/lib/rubygems/commands/server_command.rb +1 -1
  38. data/lib/rubygems/commands/setup_command.rb +124 -38
  39. data/lib/rubygems/commands/sources_command.rb +16 -16
  40. data/lib/rubygems/commands/specification_command.rb +11 -13
  41. data/lib/rubygems/commands/uninstall_command.rb +24 -7
  42. data/lib/rubygems/commands/unpack_command.rb +7 -3
  43. data/lib/rubygems/commands/update_command.rb +22 -36
  44. data/lib/rubygems/commands/yank_command.rb +98 -0
  45. data/lib/rubygems/compatibility.rb +51 -0
  46. data/lib/rubygems/config_file.rb +82 -54
  47. data/lib/rubygems/core_ext/kernel_gem.rb +53 -0
  48. data/lib/rubygems/core_ext/kernel_require.rb +119 -0
  49. data/lib/rubygems/defaults.rb +10 -21
  50. data/lib/rubygems/dependency.rb +61 -10
  51. data/lib/rubygems/dependency_installer.rb +157 -69
  52. data/lib/rubygems/dependency_list.rb +11 -19
  53. data/lib/rubygems/dependency_resolver.rb +562 -0
  54. data/lib/rubygems/deprecate.rb +40 -40
  55. data/lib/rubygems/errors.rb +77 -24
  56. data/lib/rubygems/exceptions.rb +25 -7
  57. data/lib/rubygems/ext/builder.rb +20 -23
  58. data/lib/rubygems/ext/configure_builder.rb +2 -2
  59. data/lib/rubygems/ext/ext_conf_builder.rb +5 -45
  60. data/lib/rubygems/ext/rake_builder.rb +2 -2
  61. data/lib/rubygems/gem_runner.rb +3 -16
  62. data/lib/rubygems/gemcutter_utilities.rb +22 -7
  63. data/lib/rubygems/indexer.rb +6 -159
  64. data/lib/rubygems/install_message.rb +12 -0
  65. data/lib/rubygems/install_update_options.rb +56 -18
  66. data/lib/rubygems/installer.rb +244 -134
  67. data/lib/rubygems/installer_test_case.rb +71 -19
  68. data/lib/rubygems/mock_gem_ui.rb +17 -0
  69. data/lib/rubygems/name_tuple.rb +110 -0
  70. data/lib/rubygems/package.rb +514 -43
  71. data/lib/rubygems/package/digest_io.rb +64 -0
  72. data/lib/rubygems/package/old.rb +147 -0
  73. data/lib/rubygems/package/tar_header.rb +18 -55
  74. data/lib/rubygems/package/tar_reader.rb +20 -3
  75. data/lib/rubygems/package/tar_writer.rb +63 -7
  76. data/lib/rubygems/package_task.rb +3 -4
  77. data/lib/rubygems/path_support.rb +14 -7
  78. data/lib/rubygems/platform.rb +19 -26
  79. data/lib/rubygems/rdoc.rb +316 -0
  80. data/lib/rubygems/remote_fetcher.rb +117 -54
  81. data/lib/rubygems/request_set.rb +182 -0
  82. data/lib/rubygems/requirement.rb +63 -26
  83. data/lib/rubygems/security.rb +295 -555
  84. data/lib/rubygems/security/policies.rb +115 -0
  85. data/lib/rubygems/security/policy.rb +227 -0
  86. data/lib/rubygems/security/signer.rb +136 -0
  87. data/lib/rubygems/security/trust_dir.rb +104 -0
  88. data/lib/rubygems/server.rb +45 -55
  89. data/lib/rubygems/source.rb +144 -0
  90. data/lib/rubygems/source_list.rb +87 -0
  91. data/lib/rubygems/source_local.rb +92 -0
  92. data/lib/rubygems/source_specific_file.rb +28 -0
  93. data/lib/rubygems/spec_fetcher.rb +116 -184
  94. data/lib/rubygems/specification.rb +731 -335
  95. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +88 -30
  96. data/lib/rubygems/ssl_certs/Entrust_net-Secure-Server-Certification-Authority.pem +90 -0
  97. data/lib/rubygems/ssl_certs/VerisignClass3PublicPrimaryCertificationAuthority-G2.pem +57 -0
  98. data/lib/rubygems/syck_hack.rb +2 -0
  99. data/lib/rubygems/test_case.rb +199 -109
  100. data/lib/rubygems/test_utilities.rb +25 -5
  101. data/lib/rubygems/uninstaller.rb +62 -20
  102. data/lib/rubygems/user_interaction.rb +10 -0
  103. data/lib/rubygems/validator.rb +33 -40
  104. data/lib/rubygems/version.rb +19 -8
  105. data/setup.rb +8 -1
  106. data/test/rubygems/alternate_cert.pem +9 -0
  107. data/test/rubygems/alternate_cert_32.pem +9 -0
  108. data/test/rubygems/alternate_key.pem +9 -0
  109. data/test/rubygems/bad_rake.rb +1 -0
  110. data/test/rubygems/child_cert.pem +9 -0
  111. data/test/rubygems/child_cert_32.pem +9 -0
  112. data/test/rubygems/child_key.pem +9 -0
  113. data/test/rubygems/data/null-type.gemspec.rz +0 -0
  114. data/test/rubygems/expired_cert.pem +9 -0
  115. data/test/rubygems/future_cert.pem +9 -0
  116. data/test/rubygems/future_cert_32.pem +9 -0
  117. data/test/rubygems/good_rake.rb +1 -0
  118. data/test/rubygems/grandchild_cert.pem +9 -0
  119. data/test/rubygems/grandchild_cert_32.pem +9 -0
  120. data/test/rubygems/grandchild_key.pem +9 -0
  121. data/test/rubygems/invalid_issuer_cert.pem +9 -0
  122. data/test/rubygems/invalid_issuer_cert_32.pem +9 -0
  123. data/test/rubygems/invalid_key.pem +9 -0
  124. data/test/rubygems/invalid_signer_cert.pem +9 -0
  125. data/test/rubygems/invalid_signer_cert_32.pem +9 -0
  126. data/test/rubygems/invalidchild_cert.pem +9 -0
  127. data/test/rubygems/invalidchild_cert_32.pem +9 -0
  128. data/test/rubygems/invalidchild_key.pem +9 -0
  129. data/test/rubygems/plugin/exception/rubygems_plugin.rb +1 -1
  130. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +1 -1
  131. data/test/rubygems/private_key.pem +7 -25
  132. data/test/rubygems/public_cert.pem +8 -18
  133. data/test/rubygems/public_cert_32.pem +10 -0
  134. data/test/rubygems/public_key.pem +4 -0
  135. data/test/rubygems/rubygems/commands/crash_command.rb +1 -1
  136. data/test/rubygems/test_config.rb +4 -6
  137. data/test/rubygems/test_deprecate.rb +76 -0
  138. data/test/rubygems/test_gem.rb +318 -83
  139. data/test/rubygems/test_gem_available_set.rb +106 -0
  140. data/test/rubygems/test_gem_command.rb +10 -0
  141. data/test/rubygems/test_gem_command_manager.rb +55 -9
  142. data/test/rubygems/test_gem_commands_build_command.rb +11 -19
  143. data/test/rubygems/test_gem_commands_cert_command.rb +441 -42
  144. data/test/rubygems/test_gem_commands_cleanup_command.rb +29 -1
  145. data/test/rubygems/test_gem_commands_contents_command.rb +23 -0
  146. data/test/rubygems/test_gem_commands_dependency_command.rb +5 -0
  147. data/test/rubygems/test_gem_commands_fetch_command.rb +19 -20
  148. data/test/rubygems/test_gem_commands_generate_index_command.rb +2 -83
  149. data/test/rubygems/test_gem_commands_help_command.rb +2 -1
  150. data/test/rubygems/test_gem_commands_install_command.rb +647 -48
  151. data/test/rubygems/test_gem_commands_mirror.rb +32 -0
  152. data/test/rubygems/test_gem_commands_owner_command.rb +4 -8
  153. data/test/rubygems/test_gem_commands_pristine_command.rb +99 -4
  154. data/test/rubygems/test_gem_commands_push_command.rb +62 -8
  155. data/test/rubygems/test_gem_commands_query_command.rb +51 -0
  156. data/test/rubygems/test_gem_commands_search_command.rb +25 -0
  157. data/test/rubygems/test_gem_commands_setup_command.rb +45 -0
  158. data/test/rubygems/test_gem_commands_sources_command.rb +21 -6
  159. data/test/rubygems/test_gem_commands_specification_command.rb +33 -1
  160. data/test/rubygems/test_gem_commands_uninstall_command.rb +91 -31
  161. data/test/rubygems/test_gem_commands_unpack_command.rb +3 -3
  162. data/test/rubygems/test_gem_commands_update_command.rb +56 -38
  163. data/test/rubygems/test_gem_commands_which_command.rb +4 -4
  164. data/test/rubygems/test_gem_commands_yank_command.rb +97 -0
  165. data/test/rubygems/test_gem_config_file.rb +66 -21
  166. data/test/rubygems/test_gem_dependency.rb +46 -0
  167. data/test/rubygems/test_gem_dependency_installer.rb +228 -18
  168. data/test/rubygems/test_gem_dependency_list.rb +0 -9
  169. data/test/rubygems/test_gem_dependency_resolver.rb +327 -0
  170. data/test/rubygems/test_gem_ext_configure_builder.rb +4 -4
  171. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +21 -49
  172. data/test/rubygems/test_gem_ext_rake_builder.rb +13 -13
  173. data/test/rubygems/test_gem_gem_runner.rb +27 -5
  174. data/test/rubygems/test_gem_gemcutter_utilities.rb +19 -0
  175. data/test/rubygems/test_gem_indexer.rb +14 -227
  176. data/test/rubygems/test_gem_install_update_options.rb +83 -3
  177. data/test/rubygems/test_gem_installer.rb +211 -236
  178. data/test/rubygems/test_gem_local_remote_options.rb +8 -2
  179. data/test/rubygems/test_gem_name_tuple.rb +15 -0
  180. data/test/rubygems/test_gem_package.rb +547 -0
  181. data/test/rubygems/test_gem_package_old.rb +37 -0
  182. data/test/rubygems/test_gem_package_tar_reader.rb +32 -0
  183. data/test/rubygems/test_gem_package_tar_writer.rb +84 -1
  184. data/test/rubygems/test_gem_path_support.rb +4 -30
  185. data/test/rubygems/test_gem_platform.rb +3 -6
  186. data/test/rubygems/test_gem_rdoc.rb +245 -0
  187. data/test/rubygems/test_gem_remote_fetcher.rb +51 -5
  188. data/test/rubygems/test_gem_request_set.rb +70 -0
  189. data/test/rubygems/test_gem_requirement.rb +53 -24
  190. data/test/rubygems/test_gem_security.rb +189 -43
  191. data/test/rubygems/test_gem_security_policy.rb +376 -0
  192. data/test/rubygems/test_gem_security_signer.rb +184 -0
  193. data/test/rubygems/test_gem_security_trust_dir.rb +94 -0
  194. data/test/rubygems/test_gem_server.rb +31 -36
  195. data/test/rubygems/test_gem_silent_ui.rb +2 -2
  196. data/test/rubygems/test_gem_source.rb +188 -0
  197. data/test/rubygems/test_gem_source_list.rb +87 -0
  198. data/test/rubygems/test_gem_source_local.rb +83 -0
  199. data/test/rubygems/test_gem_source_specific_file.rb +33 -0
  200. data/test/rubygems/test_gem_spec_fetcher.rb +91 -255
  201. data/test/rubygems/test_gem_specification.rb +293 -39
  202. data/test/rubygems/test_gem_uninstaller.rb +136 -13
  203. data/test/rubygems/test_gem_validator.rb +14 -41
  204. data/test/rubygems/test_gem_version.rb +15 -21
  205. data/test/rubygems/test_require.rb +193 -0
  206. data/test/rubygems/wrong_key_cert.pem +9 -0
  207. data/test/rubygems/wrong_key_cert_32.pem +9 -0
  208. metadata +171 -83
  209. metadata.gz.sig +1 -0
  210. data/CVE-2013-4287.txt +0 -36
  211. data/CVE-2013-4363.txt +0 -45
  212. data/ci_build.sh +0 -27
  213. data/cruise_config.rb +0 -32
  214. data/lib/rbconfig/datadir.rb +0 -13
  215. data/lib/rubygems/builder.rb +0 -99
  216. data/lib/rubygems/custom_require.rb +0 -69
  217. data/lib/rubygems/doc_manager.rb +0 -243
  218. data/lib/rubygems/format.rb +0 -82
  219. data/lib/rubygems/gem_openssl.rb +0 -90
  220. data/lib/rubygems/gem_path_searcher.rb +0 -172
  221. data/lib/rubygems/old_format.rb +0 -153
  222. data/lib/rubygems/package/f_sync_dir.rb +0 -23
  223. data/lib/rubygems/package/tar_input.rb +0 -234
  224. data/lib/rubygems/package/tar_output.rb +0 -146
  225. data/lib/rubygems/require_paths_builder.rb +0 -18
  226. data/lib/rubygems/source_index.rb +0 -406
  227. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  228. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  229. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  230. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  231. data/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem +0 -20
  232. data/test/rubygems/test_bundled_ca.rb +0 -59
  233. data/test/rubygems/test_gem_builder.rb +0 -44
  234. data/test/rubygems/test_gem_doc_manager.rb +0 -32
  235. data/test/rubygems/test_gem_ext_builder.rb +0 -58
  236. data/test/rubygems/test_gem_format.rb +0 -88
  237. data/test/rubygems/test_gem_gem_path_searcher.rb +0 -94
  238. data/test/rubygems/test_gem_package_tar_input.rb +0 -129
  239. data/test/rubygems/test_gem_package_tar_output.rb +0 -101
  240. data/test/rubygems/test_gem_source_index.rb +0 -250
  241. data/util/update_bundled_ca_certificates.rb +0 -103
@@ -1,23 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #--
3
- # Copyright (C) 2004 Mauricio Julio Fernández Pradier
4
- # See LICENSE.txt for additional licensing information.
5
- #++
6
-
7
- module Gem::Package::FSyncDir
8
-
9
- private
10
-
11
- ##
12
- # make sure this hits the disc
13
-
14
- def fsync_dir(dirname)
15
- dir = open dirname, 'r'
16
- dir.fsync
17
- rescue # ignore IOError if it's an unpatched (old) Ruby
18
- ensure
19
- dir.close if dir rescue nil
20
- end
21
-
22
- end
23
-
@@ -1,234 +0,0 @@
1
- # -*- coding: iso-8859-1 -*-
2
- #++
3
- # Copyright (C) 2004 Mauricio Julio Fern�ndez Pradier
4
- # See LICENSE.txt for additional licensing information.
5
- #--
6
-
7
- require 'zlib'
8
-
9
- class Gem::Package::TarInput
10
-
11
- include Gem::Package::FSyncDir
12
- include Enumerable
13
-
14
- attr_reader :metadata
15
-
16
- private_class_method :new
17
-
18
- def self.open(io, security_policy = nil, &block)
19
- is = new io, security_policy
20
-
21
- yield is
22
- ensure
23
- is.close if is
24
- end
25
-
26
- def initialize(io, security_policy = nil)
27
- @io = io
28
- @tarreader = Gem::Package::TarReader.new @io
29
- has_meta = false
30
-
31
- data_sig, meta_sig, data_dgst, meta_dgst = nil, nil, nil, nil
32
- dgst_algo = security_policy ? Gem::Security::OPT[:dgst_algo] : nil
33
-
34
- @tarreader.each do |entry|
35
- case entry.full_name
36
- when "metadata"
37
- @metadata = load_gemspec entry.read
38
- has_meta = true
39
- when "metadata.gz"
40
- begin
41
- # if we have a security_policy, then pre-read the metadata file
42
- # and calculate it's digest
43
- sio = nil
44
- if security_policy
45
- Gem.ensure_ssl_available
46
- sio = StringIO.new(entry.read)
47
- meta_dgst = dgst_algo.digest(sio.string)
48
- sio.rewind
49
- end
50
-
51
- # Ruby 1.8 doesn't have encoding and YAML is UTF-8
52
- args = [sio || entry]
53
- args << { :external_encoding => Encoding::UTF_8 } if
54
- Object.const_defined?(:Encoding)
55
-
56
- gzis = Zlib::GzipReader.new(*args)
57
-
58
- # YAML wants an instance of IO
59
- @metadata = load_gemspec(gzis)
60
- has_meta = true
61
- ensure
62
- gzis.close unless gzis.nil?
63
- end
64
- when 'metadata.gz.sig'
65
- meta_sig = entry.read
66
- when 'data.tar.gz.sig'
67
- data_sig = entry.read
68
- when 'data.tar.gz'
69
- if security_policy
70
- Gem.ensure_ssl_available
71
- data_dgst = dgst_algo.digest(entry.read)
72
- end
73
- end
74
- end
75
-
76
- if security_policy then
77
- Gem.ensure_ssl_available
78
-
79
- # map trust policy from string to actual class (or a serialized YAML
80
- # file, if that exists)
81
- if String === security_policy then
82
- if Gem::Security::Policies.key? security_policy then
83
- # load one of the pre-defined security policies
84
- security_policy = Gem::Security::Policies[security_policy]
85
- elsif File.exist? security_policy then
86
- # FIXME: this doesn't work yet
87
- security_policy = YAML.load File.read(security_policy)
88
- else
89
- raise Gem::Exception, "Unknown trust policy '#{security_policy}'"
90
- end
91
- end
92
-
93
- if data_sig && data_dgst && meta_sig && meta_dgst then
94
- # the user has a trust policy, and we have a signed gem
95
- # file, so use the trust policy to verify the gem signature
96
-
97
- begin
98
- security_policy.verify_gem(data_sig, data_dgst, @metadata.cert_chain)
99
- rescue Exception => e
100
- raise "Couldn't verify data signature: #{e}"
101
- end
102
-
103
- begin
104
- security_policy.verify_gem(meta_sig, meta_dgst, @metadata.cert_chain)
105
- rescue Exception => e
106
- raise "Couldn't verify metadata signature: #{e}"
107
- end
108
- elsif security_policy.only_signed
109
- raise Gem::Exception, "Unsigned gem"
110
- else
111
- # FIXME: should display warning here (trust policy, but
112
- # either unsigned or badly signed gem file)
113
- end
114
- end
115
-
116
- @tarreader.rewind
117
-
118
- unless has_meta then
119
- path = io.path if io.respond_to? :path
120
- error = Gem::Package::FormatError.new 'no metadata found', path
121
- raise error
122
- end
123
- end
124
-
125
- def close
126
- @io.close
127
- @tarreader.close
128
- end
129
-
130
- def each(&block)
131
- @tarreader.each do |entry|
132
- next unless entry.full_name == "data.tar.gz"
133
- is = zipped_stream entry
134
-
135
- begin
136
- Gem::Package::TarReader.new is do |inner|
137
- inner.each(&block)
138
- end
139
- ensure
140
- is.close if is
141
- end
142
- end
143
-
144
- @tarreader.rewind
145
- end
146
-
147
- def extract_entry(destdir, entry, expected_md5sum = nil)
148
- if entry.directory? then
149
- dest = File.join destdir, entry.full_name
150
-
151
- if File.directory? dest then
152
- FileUtils.chmod entry.header.mode, dest, :verbose => false
153
- else
154
- FileUtils.mkdir_p dest, :mode => entry.header.mode, :verbose => false
155
- end
156
-
157
- fsync_dir dest
158
- fsync_dir File.join(dest, "..")
159
-
160
- return
161
- end
162
-
163
- # it's a file
164
- md5 = Digest::MD5.new if expected_md5sum
165
- destdir = File.join destdir, File.dirname(entry.full_name)
166
- FileUtils.mkdir_p destdir, :mode => 0755, :verbose => false
167
- destfile = File.join destdir, File.basename(entry.full_name)
168
- FileUtils.chmod 0600, destfile, :verbose => false rescue nil # Errno::ENOENT
169
-
170
- open destfile, "wb", entry.header.mode do |os|
171
- loop do
172
- data = entry.read 4096
173
- break unless data
174
- # HACK shouldn't we check the MD5 before writing to disk?
175
- md5 << data if expected_md5sum
176
- os.write(data)
177
- end
178
-
179
- os.fsync
180
- end
181
-
182
- FileUtils.chmod entry.header.mode, destfile, :verbose => false
183
- fsync_dir File.dirname(destfile)
184
- fsync_dir File.join(File.dirname(destfile), "..")
185
-
186
- if expected_md5sum && expected_md5sum != md5.hexdigest then
187
- raise Gem::Package::BadCheckSum
188
- end
189
- end
190
-
191
- # Attempt to YAML-load a gemspec from the given _io_ parameter. Return
192
- # nil if it fails.
193
- def load_gemspec(io)
194
- Gem::Specification.from_yaml io
195
- rescue Gem::Exception
196
- nil
197
- end
198
-
199
- ##
200
- # Return an IO stream for the zipped entry.
201
- #
202
- # NOTE: Originally this method used two approaches, Return a GZipReader
203
- # directly, or read the GZipReader into a string and return a StringIO on
204
- # the string. The string IO approach was used for versions of ZLib before
205
- # 1.2.1 to avoid buffer errors on windows machines. Then we found that
206
- # errors happened with 1.2.1 as well, so we changed the condition. Then
207
- # we discovered errors occurred with versions as late as 1.2.3. At this
208
- # point (after some benchmarking to show we weren't seriously crippling
209
- # the unpacking speed) we threw our hands in the air and declared that
210
- # this method would use the String IO approach on all platforms at all
211
- # times. And that's the way it is.
212
- #
213
- # Revisited. Here's the beginning of the long story.
214
- # http://osdir.com/ml/lang.ruby.gems.devel/2007-06/msg00045.html
215
- #
216
- # StringIO wraping has never worked as a workaround by definition. Skipping
217
- # initial 10 bytes and passing -MAX_WBITS to Zlib::Inflate luckily works as
218
- # gzip reader, but it only works if the GZip header is 10 bytes long (see
219
- # below) and it does not check inflated stream consistency (CRC value in the
220
- # Gzip trailer.)
221
- #
222
- # RubyGems generated Gzip Header: 10 bytes
223
- # magic(2) + method(1) + flag(1) + mtime(4) + exflag(1) + os(1) +
224
- # orig_name(0) + comment(0)
225
- #
226
- # Ideally, it must return a GZipReader without meaningless buffering. We
227
- # have lots of CRuby committers around so let's fix windows build when we
228
- # received an error.
229
- def zipped_stream(entry)
230
- Zlib::GzipReader.new entry
231
- end
232
-
233
- end
234
-
@@ -1,146 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #--
3
- # Copyright (C) 2004 Mauricio Julio Fernández Pradier
4
- # See LICENSE.txt for additional licensing information.
5
- #++
6
-
7
- ##
8
- # TarOutput is a wrapper to TarWriter that builds gem-format tar file.
9
- #
10
- # Gem-format tar files contain the following files:
11
- # [data.tar.gz] A gzipped tar file containing the files that compose the gem
12
- # which will be extracted into the gem/ dir on installation.
13
- # [metadata.gz] A YAML format Gem::Specification.
14
- # [data.tar.gz.sig] A signature for the gem's data.tar.gz.
15
- # [metadata.gz.sig] A signature for the gem's metadata.gz.
16
- #
17
- # See TarOutput::open for usage details.
18
-
19
- class Gem::Package::TarOutput
20
-
21
- ##
22
- # Creates a new TarOutput which will yield a TarWriter object for the
23
- # data.tar.gz portion of a gem-format tar file.
24
- #
25
- # See #initialize for details on +io+ and +signer+.
26
- #
27
- # See #add_gem_contents for details on adding metadata to the tar file.
28
-
29
- def self.open(io, signer = nil, &block) # :yield: data_tar_writer
30
- tar_outputter = new io, signer
31
- tar_outputter.add_gem_contents(&block)
32
- tar_outputter.add_metadata
33
- tar_outputter.add_signatures
34
-
35
- ensure
36
- tar_outputter.close
37
- end
38
-
39
- ##
40
- # Creates a new TarOutput that will write a gem-format tar file to +io+. If
41
- # +signer+ is given, the data.tar.gz and metadata.gz will be signed and
42
- # the signatures will be added to the tar file.
43
-
44
- def initialize(io, signer)
45
- @io = io
46
- @signer = signer
47
-
48
- @tar_writer = Gem::Package::TarWriter.new @io
49
-
50
- @metadata = nil
51
-
52
- @data_signature = nil
53
- @meta_signature = nil
54
- end
55
-
56
- ##
57
- # Yields a TarWriter for the data.tar.gz inside a gem-format tar file.
58
- # The yielded TarWriter has been extended with a #metadata= method for
59
- # attaching a YAML format Gem::Specification which will be written by
60
- # add_metadata.
61
-
62
- def add_gem_contents
63
- @tar_writer.add_file "data.tar.gz", 0644 do |inner|
64
- sio = @signer ? StringIO.new : nil
65
- Zlib::GzipWriter.wrap(sio || inner) do |os|
66
-
67
- Gem::Package::TarWriter.new os do |data_tar_writer|
68
- # :stopdoc:
69
- def data_tar_writer.metadata() @metadata end
70
- def data_tar_writer.metadata=(metadata) @metadata = metadata end
71
- # :startdoc:
72
-
73
- yield data_tar_writer
74
-
75
- @metadata = data_tar_writer.metadata
76
- end
77
- end
78
-
79
- # if we have a signing key, then sign the data
80
- # digest and return the signature
81
- if @signer then
82
- require 'rubygems/security'
83
- digest = Gem::Security::OPT[:dgst_algo].digest sio.string
84
- @data_signature = @signer.sign digest
85
- inner.write sio.string
86
- end
87
- end
88
-
89
- self
90
- end
91
-
92
- ##
93
- # Adds metadata.gz to the gem-format tar file which was saved from a
94
- # previous #add_gem_contents call.
95
-
96
- def add_metadata
97
- return if @metadata.nil?
98
-
99
- @tar_writer.add_file "metadata.gz", 0644 do |io|
100
- begin
101
- sio = @signer ? StringIO.new : nil
102
- gzos = Zlib::GzipWriter.new(sio || io)
103
- gzos.write @metadata
104
- ensure
105
- gzos.flush
106
- gzos.finish
107
-
108
- # if we have a signing key, then sign the metadata digest and return
109
- # the signature
110
- if @signer then
111
- require 'rubygems/security'
112
- digest = Gem::Security::OPT[:dgst_algo].digest sio.string
113
- @meta_signature = @signer.sign digest
114
- io.write sio.string
115
- end
116
- end
117
- end
118
- end
119
-
120
- ##
121
- # Adds data.tar.gz.sig and metadata.gz.sig to the gem-format tar files if
122
- # a Gem::Security::Signer was sent to initialize.
123
-
124
- def add_signatures
125
- if @data_signature then
126
- @tar_writer.add_file 'data.tar.gz.sig', 0644 do |io|
127
- io.write @data_signature
128
- end
129
- end
130
-
131
- if @meta_signature then
132
- @tar_writer.add_file 'metadata.gz.sig', 0644 do |io|
133
- io.write @meta_signature
134
- end
135
- end
136
- end
137
-
138
- ##
139
- # Closes the TarOutput.
140
-
141
- def close
142
- @tar_writer.close
143
- end
144
-
145
- end
146
-
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
-
3
- # TODO: remove after 1.9.1 dropped
4
- module Gem::RequirePathsBuilder
5
- def write_require_paths_file_if_needed(spec = @spec, gem_home = @gem_home)
6
- return if spec.require_paths == ["lib"] &&
7
- (spec.bindir.nil? || spec.bindir == "bin")
8
- file_name = File.join(gem_home, 'gems', "#{@spec.full_name}", ".require_paths")
9
- file_name.untaint
10
- File.open(file_name, "w") do |file|
11
- spec.require_paths.each do |path|
12
- file.puts path
13
- end
14
- file.puts spec.bindir if spec.bindir
15
- end
16
- end
17
- end if Gem::QUICKLOADER_SUCKAGE
18
-
@@ -1,406 +0,0 @@
1
- #--
2
- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #++
6
-
7
- require 'rubygems/specification'
8
- require 'rubygems/deprecate'
9
-
10
- ##
11
- # The SourceIndex object indexes all the gems available from a
12
- # particular source (e.g. a list of gem directories, or a remote
13
- # source). A SourceIndex maps a gem full name to a gem
14
- # specification.
15
- #
16
- # NOTE:: The class used to be named Cache, but that became
17
- # confusing when cached source fetchers where introduced. The
18
- # constant Gem::Cache is an alias for this class to allow old
19
- # YAMLized source index objects to load properly.
20
-
21
- class Gem::SourceIndex
22
-
23
- include Enumerable
24
-
25
- attr_reader :gems # :nodoc:
26
-
27
- ##
28
- # Directories to use to refresh this SourceIndex when calling refresh!
29
-
30
- attr_accessor :spec_dirs
31
-
32
- ##
33
- # Factory method to construct a source index instance for a given
34
- # path.
35
- #
36
- # deprecated::
37
- # If supplied, from_installed_gems will act just like
38
- # +from_gems_in+. This argument is deprecated and is provided
39
- # just for backwards compatibility, and should not generally
40
- # be used.
41
- #
42
- # return::
43
- # SourceIndex instance
44
-
45
- def self.from_installed_gems(*deprecated)
46
- if deprecated.empty?
47
- from_gems_in(*installed_spec_directories)
48
- else
49
- warn "NOTE: from_installed_gems(arg) is deprecated. From #{caller.first}"
50
- from_gems_in(*deprecated) # HACK warn
51
- end
52
- end
53
-
54
- ##
55
- # Returns a list of directories from Gem.path that contain specifications.
56
-
57
- def self.installed_spec_directories
58
- # TODO: move to Gem::Utils
59
- Gem.path.collect { |dir| File.join(dir, "specifications") }
60
- end
61
-
62
- ##
63
- # Creates a new SourceIndex from the ruby format gem specifications in
64
- # +spec_dirs+.
65
-
66
- def self.from_gems_in(*spec_dirs)
67
- new spec_dirs
68
- end
69
-
70
- ##
71
- # Loads a ruby-format specification from +file_name+ and returns the
72
- # loaded spec.
73
-
74
- def self.load_specification(file_name)
75
- Gem::Deprecate.skip_during do
76
- Gem::Specification.load Gem::Path.new(file_name)
77
- end
78
- end
79
-
80
- ##
81
- # Constructs a source index instance from the provided specifications, which
82
- # is a Hash of gem full names and Gem::Specifications.
83
-
84
- def initialize specs_or_dirs = []
85
- @gems = {}
86
- @spec_dirs = nil
87
-
88
- case specs_or_dirs
89
- when Hash then
90
- specs_or_dirs.each do |full_name, spec|
91
- add_spec spec
92
- end
93
- when Array, String then
94
- self.spec_dirs = Array(specs_or_dirs)
95
- refresh!
96
- else
97
- arg = specs_or_dirs.inspect
98
- warn "NOTE: SourceIndex.new(#{arg}) is deprecated; From #{caller.first}."
99
- end
100
- end
101
-
102
- def all_gems
103
- gems
104
- end
105
-
106
- def prerelease_gems
107
- @gems.reject { |name, gem| !gem.version.prerelease? }
108
- end
109
-
110
- def released_gems
111
- @gems.reject { |name, gem| gem.version.prerelease? }
112
- end
113
-
114
- ##
115
- # Reconstruct the source index from the specifications in +spec_dirs+.
116
-
117
- def load_gems_in(*spec_dirs)
118
- @gems.clear
119
-
120
- spec_dirs.reverse_each do |spec_dir|
121
- spec_files = Dir[File.join(spec_dir, "*.gemspec")]
122
-
123
- spec_files.each do |spec_file|
124
- gemspec = Gem::Deprecate.skip_during do
125
- Gem::Specification.load spec_file
126
- end
127
- add_spec gemspec if gemspec
128
- end
129
- end
130
-
131
- self
132
- end
133
-
134
- ##
135
- # Returns an Array specifications for the latest released versions
136
- # of each gem in this index.
137
-
138
- def latest_specs(include_prerelease=false)
139
- result = Hash.new { |h,k| h[k] = [] }
140
- latest = {}
141
-
142
- sort.each do |_, spec|
143
- name = spec.name
144
- curr_ver = spec.version
145
- prev_ver = latest.key?(name) ? latest[name].version : nil
146
-
147
- next if !include_prerelease && curr_ver.prerelease?
148
- next unless prev_ver.nil? or curr_ver >= prev_ver or
149
- latest[name].platform != Gem::Platform::RUBY
150
-
151
- if prev_ver.nil? or
152
- (curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
153
- result[name].clear
154
- latest[name] = spec
155
- end
156
-
157
- if spec.platform != Gem::Platform::RUBY then
158
- result[name].delete_if do |result_spec|
159
- result_spec.platform == spec.platform
160
- end
161
- end
162
-
163
- result[name] << spec
164
- end
165
-
166
- result.values.flatten
167
- end
168
-
169
- ##
170
- # An array including only the prerelease gemspecs
171
-
172
- def prerelease_specs
173
- prerelease_gems.values
174
- end
175
-
176
- ##
177
- # An array including only the released gemspecs
178
-
179
- def released_specs
180
- released_gems.values
181
- end
182
-
183
- ##
184
- # Add a gem specification to the source index.
185
-
186
- def add_spec(gem_spec, name = gem_spec.full_name)
187
- # No idea why, but the Indexer wants to insert them using original_name
188
- # instead of full_name. So we make it an optional arg.
189
- @gems[name] = gem_spec
190
- end
191
-
192
- ##
193
- # Add gem specifications to the source index.
194
-
195
- def add_specs(*gem_specs)
196
- Gem::Deprecate.skip_during do
197
- gem_specs.each do |spec|
198
- add_spec spec
199
- end
200
- end
201
- end
202
-
203
- ##
204
- # Remove a gem specification named +full_name+.
205
-
206
- def remove_spec(full_name)
207
- @gems.delete full_name
208
- end
209
-
210
- ##
211
- # Iterate over the specifications in the source index.
212
-
213
- def each(&block) # :yields: gem.full_name, gem
214
- @gems.each(&block)
215
- end
216
-
217
- ##
218
- # The gem specification given a full gem spec name.
219
-
220
- def specification(full_name)
221
- @gems[full_name]
222
- end
223
-
224
- ##
225
- # The signature for the source index. Changes in the signature indicate a
226
- # change in the index.
227
-
228
- def index_signature
229
- require 'digest'
230
-
231
- Digest::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
232
- end
233
-
234
- ##
235
- # The signature for the given gem specification.
236
-
237
- def gem_signature(gem_full_name)
238
- require 'digest'
239
-
240
- Digest::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
241
- end
242
-
243
- def size
244
- @gems.size
245
- end
246
- alias length size
247
-
248
- ##
249
- # Find a gem by an exact match on the short name.
250
-
251
- def find_name(gem_name, requirement = Gem::Requirement.default)
252
- dep = Gem::Dependency.new gem_name, requirement
253
-
254
- Gem::Deprecate.skip_during do
255
- search dep
256
- end
257
- end
258
-
259
- ##
260
- # Search for a gem by Gem::Dependency +gem_pattern+. If +only_platform+
261
- # is true, only gems matching Gem::Platform.local will be returned. An
262
- # Array of matching Gem::Specification objects is returned.
263
- #
264
- # For backwards compatibility, a String or Regexp pattern may be passed as
265
- # +gem_pattern+, and a Gem::Requirement for +platform_only+. This
266
- # behavior is deprecated and will be removed.
267
-
268
- def search(gem_pattern, platform_or_requirement = false)
269
- requirement = nil
270
- only_platform = false # FIX: WTF is this?!?
271
-
272
- # TODO - Remove support and warning for legacy arguments after 2008/11
273
- unless Gem::Dependency === gem_pattern
274
- warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
275
- end
276
-
277
- case gem_pattern
278
- when Regexp then
279
- requirement = platform_or_requirement || Gem::Requirement.default
280
- when Gem::Dependency then
281
- only_platform = platform_or_requirement
282
- requirement = gem_pattern.requirement
283
-
284
- gem_pattern = if Regexp === gem_pattern.name then
285
- gem_pattern.name
286
- elsif gem_pattern.name.empty? then
287
- //
288
- else
289
- /^#{Regexp.escape gem_pattern.name}$/
290
- end
291
- else
292
- requirement = platform_or_requirement || Gem::Requirement.default
293
- gem_pattern = /#{gem_pattern}/i
294
- end
295
-
296
- unless Gem::Requirement === requirement then
297
- requirement = Gem::Requirement.create requirement
298
- end
299
-
300
- specs = @gems.values.select do |spec|
301
- spec.name =~ gem_pattern and
302
- requirement.satisfied_by? spec.version
303
- end
304
-
305
- if only_platform then
306
- specs = specs.select do |spec|
307
- Gem::Platform.match spec.platform
308
- end
309
- end
310
-
311
- specs.sort_by { |s| s.sort_obj }
312
- end
313
-
314
- ##
315
- # Replaces the gems in the source index from specifications in the
316
- # directories this source index was created from. Raises an exception if
317
- # this source index wasn't created from a directory (via from_gems_in or
318
- # from_installed_gems, or having spec_dirs set).
319
-
320
- def refresh!
321
- raise 'source index not created from disk' if @spec_dirs.nil?
322
- load_gems_in(*@spec_dirs)
323
- end
324
-
325
- ##
326
- # Returns an Array of Gem::Specifications that are not up to date.
327
-
328
- def outdated
329
- outdateds = []
330
-
331
- latest_specs.each do |local|
332
- dependency = Gem::Dependency.new local.name, ">= #{local.version}"
333
-
334
- fetcher = Gem::SpecFetcher.fetcher
335
- remotes = fetcher.find_matching dependency
336
- remotes = remotes.map { |(_, version, _), _| version }
337
-
338
- latest = remotes.sort.last
339
-
340
- outdateds << local.name if latest and local.version < latest
341
- end
342
-
343
- outdateds
344
- end
345
-
346
- def ==(other) # :nodoc:
347
- self.class === other and @gems == other.gems
348
- end
349
-
350
- def dump
351
- Marshal.dump(self)
352
- end
353
- end
354
-
355
- # :stopdoc:
356
- module Gem
357
-
358
- ##
359
- # Cache is an alias for SourceIndex to allow older YAMLized source index
360
- # objects to load properly.
361
-
362
- Cache = SourceIndex
363
-
364
- end
365
-
366
- class Gem::SourceIndex
367
- extend Gem::Deprecate
368
-
369
- deprecate :all_gems, :none, 2011, 10
370
-
371
- deprecate :==, :none, 2011, 11 # noisy
372
- deprecate :add_specs, :none, 2011, 11 # noisy
373
- deprecate :each, :none, 2011, 11
374
- deprecate :gems, :none, 2011, 11
375
- deprecate :load_gems_in, :none, 2011, 11
376
- deprecate :refresh!, :none, 2011, 11
377
- deprecate :spec_dirs=, "Specification.dirs=", 2011, 11 # noisy
378
- deprecate :add_spec, "Specification.add_spec", 2011, 11
379
- deprecate :find_name, "Specification.find_by_name", 2011, 11
380
- deprecate :gem_signature, :none, 2011, 11
381
- deprecate :index_signature, :none, 2011, 11
382
- deprecate :initialize, :none, 2011, 11
383
- deprecate :latest_specs, "Specification.latest_specs", 2011, 11
384
- deprecate :length, "Specification.all.length", 2011, 11
385
- deprecate :outdated, :none, 2011, 11
386
- deprecate :prerelease_gems, :none, 2011, 11
387
- deprecate :prerelease_specs, :none, 2011, 11
388
- deprecate :released_gems, :none, 2011, 11
389
- deprecate :released_specs, :none, 2011, 11
390
- deprecate :remove_spec, "Specification.remove_spec", 2011, 11
391
- deprecate :search, :none, 2011, 11
392
- deprecate :size, "Specification.all.size", 2011, 11
393
- deprecate :spec_dirs, "Specification.dirs", 2011, 11
394
- deprecate :specification, "Specification.find", 2011, 11
395
-
396
- class << self
397
- extend Gem::Deprecate
398
-
399
- deprecate :from_gems_in, :none, 2011, 10
400
- deprecate :from_installed_gems, :none, 2011, 10
401
- deprecate :installed_spec_directories, "Specification.dirs", 2011, 11
402
- deprecate :load_specification, :none, 2011, 10
403
- end
404
- end
405
-
406
- # :startdoc: