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
@@ -0,0 +1,64 @@
1
+ ##
2
+ # IO wrapper that creates digests of contents written to the IO it wraps.
3
+
4
+ class Gem::Package::DigestIO
5
+
6
+ ##
7
+ # Collected digests for wrapped writes.
8
+ #
9
+ # {
10
+ # 'SHA1' => #<OpenSSL::Digest: [...]>,
11
+ # 'SHA512' => #<OpenSSL::Digest: [...]>,
12
+ # }
13
+
14
+ attr_reader :digests
15
+
16
+ ##
17
+ # Wraps +io+ and updates digest for each of the digest algorithms in
18
+ # the +digests+ Hash. Returns the digests hash. Example:
19
+ #
20
+ # io = StringIO.new
21
+ # digests = {
22
+ # 'SHA1' => OpenSSL::Digest.new('SHA1'),
23
+ # 'SHA512' => OpenSSL::Digest.new('SHA512'),
24
+ # }
25
+ #
26
+ # Gem::Package::DigestIO.wrap io, digests do |digest_io|
27
+ # digest_io.write "hello"
28
+ # end
29
+ #
30
+ # digests['SHA1'].hexdigest #=> "aaf4c61d[...]"
31
+ # digests['SHA512'].hexdigest #=> "9b71d224[...]"
32
+
33
+ def self.wrap io, digests
34
+ digest_io = new io, digests
35
+
36
+ yield digest_io
37
+
38
+ return digests
39
+ end
40
+
41
+ ##
42
+ # Creates a new DigestIO instance. Using ::wrap is recommended, see the
43
+ # ::wrap documentation for documentation of +io+ and +digests+.
44
+
45
+ def initialize io, digests
46
+ @io = io
47
+ @digests = digests
48
+ end
49
+
50
+ ##
51
+ # Writes +data+ to the underlying IO and updates the digests
52
+
53
+ def write data
54
+ result = @io.write data
55
+
56
+ @digests.each do |_, digest|
57
+ digest << data
58
+ end
59
+
60
+ result
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,147 @@
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
+ ##
8
+ # The format class knows the guts of the ancient .gem file format and provides
9
+ # the capability to read such ancient gems.
10
+ #
11
+ # Please pretend this doesn't exist.
12
+
13
+ class Gem::Package::Old < Gem::Package
14
+
15
+ undef_method :spec=
16
+
17
+ ##
18
+ # Creates a new old-format package reader for +gem+. Old-format packages
19
+ # cannot be written.
20
+
21
+ def initialize gem
22
+ require 'fileutils'
23
+ require 'zlib'
24
+ Gem.load_yaml
25
+
26
+ @gem = gem
27
+ @contents = nil
28
+ @spec = nil
29
+ end
30
+
31
+ ##
32
+ # A list of file names contained in this gem
33
+
34
+ def contents
35
+ return @contents if @contents
36
+
37
+ open @gem, 'rb' do |io|
38
+ read_until_dashes io # spec
39
+ header = file_list io
40
+
41
+ @contents = header.map { |file| file['path'] }
42
+ end
43
+ end
44
+
45
+ ##
46
+ # Extracts the files in this package into +destination_dir+
47
+
48
+ def extract_files destination_dir
49
+ errstr = "Error reading files from gem"
50
+
51
+ open @gem, 'rb' do |io|
52
+ read_until_dashes io # spec
53
+ header = file_list io
54
+ raise Gem::Exception, errstr unless header
55
+
56
+ header.each do |entry|
57
+ full_name = entry['path']
58
+
59
+ destination = install_location full_name, destination_dir
60
+
61
+ file_data = ''
62
+
63
+ read_until_dashes io do |line|
64
+ file_data << line
65
+ end
66
+
67
+ file_data = file_data.strip.unpack("m")[0]
68
+ file_data = Zlib::Inflate.inflate file_data
69
+
70
+ raise Gem::Package::FormatError, "#{full_name} in #{@gem} is corrupt" if
71
+ file_data.length != entry['size'].to_i
72
+
73
+ FileUtils.rm_rf destination
74
+
75
+ FileUtils.mkdir_p File.dirname destination
76
+
77
+ open destination, 'wb', entry['mode'] do |out|
78
+ out.write file_data
79
+ end
80
+
81
+ say destination if Gem.configuration.really_verbose
82
+ end
83
+ end
84
+ rescue Zlib::DataError
85
+ raise Gem::Exception, errstr
86
+ end
87
+
88
+ ##
89
+ # Reads the file list section from the old-format gem +io+
90
+
91
+ def file_list io # :nodoc:
92
+ header = ''
93
+
94
+ read_until_dashes io do |line|
95
+ header << line
96
+ end
97
+
98
+ YAML.load header
99
+ end
100
+
101
+ ##
102
+ # Reads lines until a "---" separator is found
103
+
104
+ def read_until_dashes io # :nodoc:
105
+ while (line = io.gets) && line.chomp.strip != "---" do
106
+ yield line if block_given?
107
+ end
108
+ end
109
+
110
+ ##
111
+ # Skips the Ruby self-install header in +io+.
112
+
113
+ def skip_ruby io # :nodoc:
114
+ loop do
115
+ line = io.gets
116
+
117
+ return if line.chomp == '__END__'
118
+ break unless line
119
+ end
120
+
121
+ raise Gem::Exception, "Failed to find end of ruby script while reading gem"
122
+ end
123
+
124
+ ##
125
+ # The specification for this gem
126
+
127
+ def spec
128
+ return @spec if @spec
129
+
130
+ yaml = ''
131
+
132
+ open @gem, 'rb' do |io|
133
+ skip_ruby io
134
+ read_until_dashes io do |line|
135
+ yaml << line
136
+ end
137
+ end
138
+
139
+ @spec = Gem::Specification.from_yaml yaml
140
+ rescue YAML::SyntaxError => e
141
+ raise Gem::Exception, "Failed to parse gem specification out of gem file"
142
+ rescue ArgumentError => e
143
+ raise Gem::Exception, "Failed to parse gem specification out of gem file"
144
+ end
145
+
146
+ end
147
+
@@ -102,61 +102,24 @@ class Gem::Package::TarHeader
102
102
 
103
103
  fields = header.unpack UNPACK_FORMAT
104
104
 
105
- name = fields.shift
106
- mode = fields.shift.oct
107
- uid = fields.shift.oct
108
- gid = fields.shift.oct
109
- size = fields.shift.oct
110
- mtime = fields.shift.oct
111
- checksum = fields.shift.oct
112
- typeflag = fields.shift
113
- linkname = fields.shift
114
- magic = fields.shift
115
- version = fields.shift.oct
116
- uname = fields.shift
117
- gname = fields.shift
118
- devmajor = fields.shift.oct
119
- devminor = fields.shift.oct
120
- prefix = fields.shift
121
-
122
- new :name => name,
123
- :mode => mode,
124
- :uid => uid,
125
- :gid => gid,
126
- :size => size,
127
- :mtime => mtime,
128
- :checksum => checksum,
129
- :typeflag => typeflag,
130
- :linkname => linkname,
131
- :magic => magic,
132
- :version => version,
133
- :uname => uname,
134
- :gname => gname,
135
- :devmajor => devmajor,
136
- :devminor => devminor,
137
- :prefix => prefix,
138
-
139
- :empty => empty
140
-
141
- # HACK unfactor for Rubinius
142
- #new :name => fields.shift,
143
- # :mode => fields.shift.oct,
144
- # :uid => fields.shift.oct,
145
- # :gid => fields.shift.oct,
146
- # :size => fields.shift.oct,
147
- # :mtime => fields.shift.oct,
148
- # :checksum => fields.shift.oct,
149
- # :typeflag => fields.shift,
150
- # :linkname => fields.shift,
151
- # :magic => fields.shift,
152
- # :version => fields.shift.oct,
153
- # :uname => fields.shift,
154
- # :gname => fields.shift,
155
- # :devmajor => fields.shift.oct,
156
- # :devminor => fields.shift.oct,
157
- # :prefix => fields.shift,
158
-
159
- # :empty => empty
105
+ new :name => fields.shift,
106
+ :mode => fields.shift.oct,
107
+ :uid => fields.shift.oct,
108
+ :gid => fields.shift.oct,
109
+ :size => fields.shift.oct,
110
+ :mtime => fields.shift.oct,
111
+ :checksum => fields.shift.oct,
112
+ :typeflag => fields.shift,
113
+ :linkname => fields.shift,
114
+ :magic => fields.shift,
115
+ :version => fields.shift.oct,
116
+ :uname => fields.shift,
117
+ :gname => fields.shift,
118
+ :devmajor => fields.shift.oct,
119
+ :devminor => fields.shift.oct,
120
+ :prefix => fields.shift,
121
+
122
+ :empty => empty
160
123
  end
161
124
 
162
125
  ##
@@ -9,7 +9,7 @@
9
9
 
10
10
  class Gem::Package::TarReader
11
11
 
12
- include Gem::Package
12
+ include Enumerable
13
13
 
14
14
  ##
15
15
  # Raised if the tar IO is not seekable
@@ -52,9 +52,9 @@ class Gem::Package::TarReader
52
52
  # Iterates over files in the tarball yielding each entry
53
53
 
54
54
  def each
55
- loop do
56
- return if @io.eof?
55
+ return enum_for __method__ unless block_given?
57
56
 
57
+ until @io.eof? do
58
58
  header = Gem::Package::TarHeader.from @io
59
59
  return if header.empty?
60
60
 
@@ -100,6 +100,23 @@ class Gem::Package::TarReader
100
100
  end
101
101
  end
102
102
 
103
+ ##
104
+ # Seeks through the tar file until it finds the +entry+ with +name+ and
105
+ # yields it. Rewinds the tar file to the beginning when the block
106
+ # terminates.
107
+
108
+ def seek name # :yields: entry
109
+ found = find do |entry|
110
+ entry.full_name == name
111
+ end
112
+
113
+ return unless found
114
+
115
+ return yield found
116
+ ensure
117
+ rewind
118
+ end
119
+
103
120
  end
104
121
 
105
122
  require 'rubygems/package/tar_reader/entry'
@@ -40,12 +40,12 @@ class Gem::Package::TarWriter
40
40
  # number of bytes will be more than #limit
41
41
 
42
42
  def write(data)
43
- if data.size + @written > @limit
43
+ if data.bytesize + @written > @limit
44
44
  raise FileOverflow, "You tried to feed more data than fits in the file."
45
45
  end
46
46
  @io.write data
47
- @written += data.size
48
- data.size
47
+ @written += data.bytesize
48
+ data.bytesize
49
49
  end
50
50
 
51
51
  end
@@ -129,6 +129,62 @@ class Gem::Package::TarWriter
129
129
  self
130
130
  end
131
131
 
132
+ ##
133
+ # Adds +name+ with permissions +mode+ to the tar, yielding +io+ for writing
134
+ # the file. The +digest_algorithm+ is written to a read-only +name+.sum
135
+ # file following the given file contents containing the digest name and
136
+ # hexdigest separated by a tab.
137
+ #
138
+ # The created digest object is returned.
139
+
140
+ def add_file_digest name, mode, digest_algorithms # :yields: io
141
+ digests = digest_algorithms.map do |digest_algorithm|
142
+ digest = digest_algorithm.new
143
+ [digest.name, digest]
144
+ end
145
+
146
+ digests = Hash[*digests.flatten]
147
+
148
+ add_file name, mode do |io|
149
+ Gem::Package::DigestIO.wrap io, digests do |digest_io|
150
+ yield digest_io
151
+ end
152
+ end
153
+
154
+ digests
155
+ end
156
+
157
+ ##
158
+ # Adds +name+ with permissions +mode+ to the tar, yielding +io+ for writing
159
+ # the file. The +signer+ is used to add a digest file using its
160
+ # digest_algorithm per add_file_digest and a cryptographic signature in
161
+ # +name+.sig. If the signer has no key only the checksum file is added.
162
+ #
163
+ # Returns the digest.
164
+
165
+ def add_file_signed name, mode, signer
166
+ digest_algorithms = [
167
+ signer.digest_algorithm,
168
+ OpenSSL::Digest::SHA512,
169
+ ].uniq
170
+
171
+ digests = add_file_digest name, mode, digest_algorithms do |io|
172
+ yield io
173
+ end
174
+
175
+ signature_digest = digests.values.find do |digest|
176
+ digest.name == signer.digest_name
177
+ end
178
+
179
+ signature = signer.sign signature_digest.digest
180
+
181
+ add_file_simple "#{name}.sig", 0444, signature.length do |io|
182
+ io.write signature
183
+ end if signature
184
+
185
+ digests
186
+ end
187
+
132
188
  ##
133
189
  # Add file +name+ with permissions +mode+ +size+ bytes long. Yields an IO
134
190
  # to write the file to.
@@ -211,9 +267,9 @@ class Gem::Package::TarWriter
211
267
  # Splits +name+ into a name and prefix that can fit in the TarHeader
212
268
 
213
269
  def split_name(name) # :nodoc:
214
- raise Gem::Package::TooLongFileName if name.size > 256
270
+ raise Gem::Package::TooLongFileName if name.bytesize > 256
215
271
 
216
- if name.size <= 100 then
272
+ if name.bytesize <= 100 then
217
273
  prefix = ""
218
274
  else
219
275
  parts = name.split(/\//)
@@ -222,14 +278,14 @@ class Gem::Package::TarWriter
222
278
 
223
279
  loop do
224
280
  nxt = parts.pop
225
- break if newname.size + 1 + nxt.size > 100
281
+ break if newname.bytesize + 1 + nxt.bytesize > 100
226
282
  newname = nxt + "/" + newname
227
283
  end
228
284
 
229
285
  prefix = (parts + [nxt]).join "/"
230
286
  name = newname
231
287
 
232
- if name.size > 100 or prefix.size > 155 then
288
+ if name.bytesize > 100 or prefix.bytesize > 155 then
233
289
  raise Gem::Package::TooLongFileName
234
290
  end
235
291
  end
@@ -20,6 +20,7 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'rubygems'
23
+ require 'rubygems/package'
23
24
  begin
24
25
  gem 'rake'
25
26
  rescue Gem::LoadError
@@ -43,13 +44,10 @@ require 'rake/packagetask'
43
44
  # require 'rubygems/package_task'
44
45
  #
45
46
  # spec = Gem::Specification.new do |s|
46
- # s.platform = Gem::Platform::RUBY
47
47
  # s.summary = "Ruby based make-like utility."
48
48
  # s.name = 'rake'
49
49
  # s.version = PKG_VERSION
50
50
  # s.requirements << 'none'
51
- # s.require_path = 'lib'
52
- # s.autorequire = 'rake'
53
51
  # s.files = PKG_FILES
54
52
  # s.description = <<-EOF
55
53
  # Rake is a Make-like program implemented in Ruby. Tasks
@@ -113,7 +111,8 @@ class Gem::PackageTask < Rake::PackageTask
113
111
  file gem_path => [package_dir, gem_dir] + @gem_spec.files do
114
112
  chdir(gem_dir) do
115
113
  when_writing "Creating #{gem_spec.file_name}" do
116
- Gem::Builder.new(gem_spec).build
114
+ Gem::Package.build gem_spec
115
+
117
116
  verbose trace do
118
117
  mv gem_file, '..'
119
118
  end