rubygems-update 1.0.1 → 1.1.0

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 (172) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +248 -0
  3. data/README +2 -0
  4. data/Rakefile +47 -23
  5. data/bin/gem +9 -4
  6. data/bin/update_rubygems +15 -1
  7. data/examples/application/bin/myapp +0 -0
  8. data/lib/rubygems.rb +506 -373
  9. data/lib/rubygems/builder.rb +14 -7
  10. data/lib/rubygems/command.rb +9 -9
  11. data/lib/rubygems/command_manager.rb +1 -0
  12. data/lib/rubygems/commands/cleanup_command.rb +67 -69
  13. data/lib/rubygems/commands/environment_command.rb +16 -10
  14. data/lib/rubygems/commands/fetch_command.rb +7 -9
  15. data/lib/rubygems/commands/install_command.rb +9 -3
  16. data/lib/rubygems/commands/list_command.rb +2 -4
  17. data/lib/rubygems/commands/mirror_command.rb +1 -1
  18. data/lib/rubygems/commands/query_command.rb +52 -5
  19. data/lib/rubygems/commands/sources_command.rb +19 -10
  20. data/lib/rubygems/commands/specification_command.rb +10 -6
  21. data/lib/rubygems/commands/uninstall_command.rb +23 -6
  22. data/lib/rubygems/commands/unpack_command.rb +15 -3
  23. data/lib/rubygems/commands/update_command.rb +27 -25
  24. data/lib/rubygems/custom_require.rb +1 -1
  25. data/lib/rubygems/defaults.rb +8 -1
  26. data/lib/rubygems/dependency_installer.rb +72 -104
  27. data/lib/rubygems/digest/digest_adapter.rb +0 -0
  28. data/lib/rubygems/digest/md5.rb +0 -0
  29. data/lib/rubygems/digest/sha1.rb +0 -0
  30. data/lib/rubygems/digest/sha2.rb +0 -0
  31. data/lib/rubygems/exceptions.rb +22 -1
  32. data/lib/rubygems/format.rb +16 -10
  33. data/lib/rubygems/indexer.rb +46 -33
  34. data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
  35. data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  36. data/lib/rubygems/indexer/master_index_builder.rb +9 -8
  37. data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
  38. data/lib/rubygems/install_update_options.rb +7 -1
  39. data/lib/rubygems/installer.rb +8 -5
  40. data/lib/rubygems/package.rb +17 -774
  41. data/lib/rubygems/package/f_sync_dir.rb +24 -0
  42. data/lib/rubygems/package/tar_header.rb +245 -0
  43. data/lib/rubygems/package/tar_input.rb +219 -0
  44. data/lib/rubygems/package/tar_output.rb +143 -0
  45. data/lib/rubygems/package/tar_reader.rb +86 -0
  46. data/lib/rubygems/package/tar_reader/entry.rb +99 -0
  47. data/lib/rubygems/package/tar_writer.rb +180 -0
  48. data/lib/rubygems/remote_fetcher.rb +131 -16
  49. data/lib/rubygems/requirement.rb +2 -0
  50. data/lib/rubygems/rubygems_version.rb +1 -1
  51. data/lib/rubygems/security.rb +1 -0
  52. data/lib/rubygems/server.rb +85 -104
  53. data/lib/rubygems/source_index.rb +412 -329
  54. data/lib/rubygems/source_info_cache.rb +232 -99
  55. data/lib/rubygems/source_info_cache_entry.rb +14 -4
  56. data/lib/rubygems/specification.rb +9 -10
  57. data/lib/rubygems/timer.rb +0 -0
  58. data/lib/rubygems/uninstaller.rb +56 -32
  59. data/lib/rubygems/user_interaction.rb +4 -10
  60. data/lib/rubygems/validator.rb +0 -0
  61. data/scripts/gemdoc.rb +0 -0
  62. data/scripts/specdoc.rb +0 -0
  63. data/setup.rb +56 -19
  64. data/test/gem_installer_test_case.rb +86 -0
  65. data/test/gem_installer_test_case.rbc +0 -0
  66. data/test/gem_package_tar_test_case.rb +146 -0
  67. data/test/gem_package_tar_test_case.rbc +0 -0
  68. data/test/gemutilities.rb +123 -38
  69. data/test/gemutilities.rbc +0 -0
  70. data/test/mockgemui.rb +5 -13
  71. data/test/mockgemui.rbc +0 -0
  72. data/test/private_key.pem +27 -0
  73. data/test/public_cert.pem +20 -0
  74. data/test/simple_gem.rbc +0 -0
  75. data/test/test_config.rbc +0 -0
  76. data/test/test_gem.rb +46 -4
  77. data/test/test_gem.rbc +0 -0
  78. data/test/test_gem_builder.rbc +0 -0
  79. data/test/test_gem_command.rbc +0 -0
  80. data/test/test_gem_command_manager.rb +4 -2
  81. data/test/test_gem_command_manager.rbc +0 -0
  82. data/test/test_gem_commands_build_command.rbc +0 -0
  83. data/test/test_gem_commands_cert_command.rb +5 -1
  84. data/test/test_gem_commands_cert_command.rbc +0 -0
  85. data/test/test_gem_commands_check_command.rbc +0 -0
  86. data/test/test_gem_commands_contents_command.rbc +0 -0
  87. data/test/test_gem_commands_dependency_command.rbc +0 -0
  88. data/test/test_gem_commands_environment_command.rb +17 -1
  89. data/test/test_gem_commands_environment_command.rbc +0 -0
  90. data/test/test_gem_commands_fetch_command.rb +6 -5
  91. data/test/test_gem_commands_fetch_command.rbc +0 -0
  92. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  93. data/test/test_gem_commands_install_command.rb +36 -28
  94. data/test/test_gem_commands_install_command.rbc +0 -0
  95. data/test/test_gem_commands_mirror_command.rbc +0 -0
  96. data/test/test_gem_commands_pristine_command.rbc +0 -0
  97. data/test/test_gem_commands_query_command.rb +143 -19
  98. data/test/test_gem_commands_query_command.rbc +0 -0
  99. data/test/test_gem_commands_server_command.rb +1 -1
  100. data/test/test_gem_commands_server_command.rbc +0 -0
  101. data/test/test_gem_commands_sources_command.rb +67 -9
  102. data/test/test_gem_commands_sources_command.rbc +0 -0
  103. data/test/test_gem_commands_specification_command.rb +3 -2
  104. data/test/test_gem_commands_specification_command.rbc +0 -0
  105. data/test/test_gem_commands_unpack_command.rb +46 -4
  106. data/test/test_gem_commands_unpack_command.rbc +0 -0
  107. data/test/test_gem_commands_update_command.rb +174 -0
  108. data/test/test_gem_commands_update_command.rbc +0 -0
  109. data/test/test_gem_config_file.rbc +0 -0
  110. data/test/test_gem_dependency.rbc +0 -0
  111. data/test/test_gem_dependency_installer.rb +172 -187
  112. data/test/test_gem_dependency_installer.rbc +0 -0
  113. data/test/test_gem_dependency_list.rbc +0 -0
  114. data/test/test_gem_digest.rb +0 -0
  115. data/test/test_gem_digest.rbc +0 -0
  116. data/test/test_gem_doc_manager.rbc +0 -0
  117. data/test/test_gem_ext_configure_builder.rb +9 -6
  118. data/test/test_gem_ext_configure_builder.rbc +0 -0
  119. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  120. data/test/test_gem_ext_rake_builder.rbc +0 -0
  121. data/test/test_gem_format.rb +1 -1
  122. data/test/test_gem_format.rbc +0 -0
  123. data/test/test_gem_gem_path_searcher.rbc +0 -0
  124. data/test/test_gem_gem_runner.rbc +0 -0
  125. data/test/test_gem_indexer.rb +7 -2
  126. data/test/test_gem_indexer.rbc +0 -0
  127. data/test/test_gem_install_update_options.rbc +0 -0
  128. data/test/test_gem_installer.rb +5 -84
  129. data/test/test_gem_installer.rbc +0 -0
  130. data/test/test_gem_local_remote_options.rbc +0 -0
  131. data/test/test_gem_outdated_command.rbc +0 -0
  132. data/test/test_gem_package_tar_header.rb +137 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rb +119 -0
  135. data/test/test_gem_package_tar_input.rbc +0 -0
  136. data/test/test_gem_package_tar_output.rb +104 -0
  137. data/test/test_gem_package_tar_output.rbc +0 -0
  138. data/test/test_gem_package_tar_reader.rb +53 -0
  139. data/test/test_gem_package_tar_reader.rbc +0 -0
  140. data/test/test_gem_package_tar_reader_entry.rb +116 -0
  141. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  142. data/test/test_gem_package_tar_writer.rb +151 -0
  143. data/test/test_gem_package_tar_writer.rbc +0 -0
  144. data/test/test_gem_platform.rbc +0 -0
  145. data/test/test_gem_remote_fetcher.rb +189 -17
  146. data/test/test_gem_remote_fetcher.rbc +0 -0
  147. data/test/test_gem_requirement.rbc +0 -0
  148. data/test/test_gem_server.rb +13 -12
  149. data/test/test_gem_server.rbc +0 -0
  150. data/test/test_gem_source_index.rb +305 -56
  151. data/test/test_gem_source_index.rbc +0 -0
  152. data/test/test_gem_source_info_cache.rb +179 -53
  153. data/test/test_gem_source_info_cache.rbc +0 -0
  154. data/test/test_gem_source_info_cache_entry.rb +41 -10
  155. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  156. data/test/test_gem_specification.rb +7 -7
  157. data/test/test_gem_specification.rbc +0 -0
  158. data/test/test_gem_stream_ui.rbc +0 -0
  159. data/test/test_gem_uninstaller.rb +43 -0
  160. data/test/test_gem_uninstaller.rbc +0 -0
  161. data/test/test_gem_validator.rbc +0 -0
  162. data/test/test_gem_version.rb +1 -1
  163. data/test/test_gem_version.rbc +0 -0
  164. data/test/test_gem_version_option.rbc +0 -0
  165. data/test/test_kernel.rb +1 -0
  166. data/test/test_kernel.rbc +0 -0
  167. metadata +85 -8
  168. metadata.gz.sig +0 -0
  169. data/lib/rubygems/gem_open_uri.rb +0 -7
  170. data/lib/rubygems/open-uri.rb +0 -773
  171. data/test/test_open_uri.rb +0 -13
  172. data/test/test_package.rb +0 -608
@@ -1,13 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems/gem_open_uri'
3
-
4
- class TestOpenURI < Test::Unit::TestCase
5
-
6
- def test_open_uri_not_broken
7
- assert_nothing_raised do
8
- open __FILE__ do end
9
- end
10
- end
11
-
12
- end
13
-
@@ -1,608 +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 'test/unit'
8
- require 'stringio'
9
- require 'fileutils'
10
-
11
- require 'rubygems'
12
- require 'rubygems/package'
13
-
14
- class File
15
-
16
- # straight from setup.rb
17
- def self.dir?(path)
18
- # for corrupted windows stat()
19
- File.directory?((path[-1,1] == '/') ? path : path + '/')
20
- end
21
-
22
- def self.read_b(name)
23
- File.open(name, "rb"){|f| f.read}
24
- end
25
-
26
- end
27
-
28
- class TarTestCase < Test::Unit::TestCase
29
-
30
- undef_method :default_test if instance_methods.include? 'default_test' or
31
- instance_methods.include? :default_test
32
-
33
- def assert_headers_equal(h1, h2)
34
- fields = %w[name 100 mode 8 uid 8 gid 8 size 12 mtime 12 checksum 8
35
- typeflag 1 linkname 100 magic 6 version 2 uname 32
36
- gname 32 devmajor 8 devminor 8 prefix 155]
37
- offset = 0
38
- until fields.empty?
39
- name = fields.shift
40
- length = fields.shift.to_i
41
- if name == "checksum"
42
- chksum_off = offset
43
- offset += length
44
- next
45
- end
46
- assert_equal(h1[offset, length], h2[offset, length],
47
- "Field #{name} of the tar header differs.")
48
- offset += length
49
- end
50
- assert_equal(h1[chksum_off, 8], h2[chksum_off, 8])
51
- end
52
-
53
- def tar_file_header(fname, dname, mode, length)
54
- h = header("0", fname, dname, length, mode)
55
- checksum = calc_checksum(h)
56
- header("0", fname, dname, length, mode, checksum)
57
- end
58
-
59
- def tar_dir_header(name, prefix, mode)
60
- h = header("5", name, prefix, 0, mode)
61
- checksum = calc_checksum(h)
62
- header("5", name, prefix, 0, mode, checksum)
63
- end
64
-
65
- def header(type, fname, dname, length, mode, checksum = nil)
66
- checksum ||= " " * 8
67
-
68
- arr = [ # struct tarfile_entry_posix
69
- ASCIIZ(fname, 100), # char name[100]; ASCII + (Z unless filled)
70
- Z(to_oct(mode, 7)), # char mode[8]; 0 padded, octal null
71
- Z(to_oct(0, 7)), # char uid[8]; ditto
72
- Z(to_oct(0, 7)), # char gid[8]; ditto
73
- Z(to_oct(length, 11)), # char size[12]; 0 padded, octal, null
74
- Z(to_oct(0, 11)), # char mtime[12]; 0 padded, octal, null
75
- checksum, # char checksum[8]; 0 padded, octal, null, space
76
- type, # char typeflag[1]; file: "0" dir: "5"
77
- "\0" * 100, # char linkname[100]; ASCII + (Z unless filled)
78
- "ustar\0", # char magic[6]; "ustar\0"
79
- "00", # char version[2]; "00"
80
- ASCIIZ("wheel", 32), # char uname[32]; ASCIIZ
81
- ASCIIZ("wheel", 32), # char gname[32]; ASCIIZ
82
- Z(to_oct(0, 7)), # char devmajor[8]; 0 padded, octal, null
83
- Z(to_oct(0, 7)), # char devminor[8]; 0 padded, octal, null
84
- ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled)
85
- ]
86
-
87
- format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155"
88
- h = if RUBY_VERSION >= "1.9" then
89
- arr.join
90
- else
91
- arr = arr.join("").split(//).map{|x| x[0]}
92
- arr.pack format
93
- end
94
- ret = h + "\0" * (512 - h.size)
95
- assert_equal(512, ret.size)
96
- ret
97
- end
98
-
99
- def calc_checksum(header)
100
- sum = header.unpack("C*").inject{|s,a| s + a}
101
- SP(Z(to_oct(sum, 6)))
102
- end
103
-
104
- def to_oct(n, pad_size)
105
- "%0#{pad_size}o" % n
106
- end
107
-
108
- def ASCIIZ(str, length)
109
- str + "\0" * (length - str.length)
110
- end
111
-
112
- def SP(s)
113
- s + " "
114
- end
115
-
116
- def Z(s)
117
- s + "\0"
118
- end
119
-
120
- def SP_Z(s)
121
- s + " \0"
122
- end
123
-
124
- end
125
-
126
- class TestTarHeader < TarTestCase
127
-
128
- def test_arguments_are_checked
129
- e = ArgumentError
130
- gpth = Gem::Package::TarHeader
131
- assert_raises(e) { gpth.new :name=>"", :size=>"", :mode=>"" }
132
- assert_raises(e) { gpth.new :name=>"", :size=>"", :prefix=>"" }
133
- assert_raises(e) { gpth.new :name=>"", :prefix=>"", :mode=>"" }
134
- assert_raises(e) { gpth.new :prefix=>"", :size=>"", :mode=>"" }
135
- end
136
-
137
- def test_basic_headers
138
- header = Gem::Package::TarHeader.new(:name => "bla", :mode => 012345,
139
- :size => 10, :prefix => "").to_s
140
- assert_headers_equal(tar_file_header("bla", "", 012345, 10), header.to_s)
141
- header = Gem::Package::TarHeader.new(:name => "bla", :mode => 012345,
142
- :size => 0, :prefix => "",
143
- :typeflag => "5" ).to_s
144
- assert_headers_equal(tar_dir_header("bla", "", 012345), header)
145
- end
146
-
147
- def test_long_name_works
148
- header = Gem::Package::TarHeader.new(:name => "a" * 100, :mode => 012345,
149
- :size => 10, :prefix => "").to_s
150
- assert_headers_equal(tar_file_header("a" * 100, "", 012345, 10), header)
151
-
152
- header = Gem::Package::TarHeader.new(:name => "a" * 100, :mode => 012345,
153
- :size => 10, :prefix => "bb" * 60).to_s
154
- assert_headers_equal(tar_file_header("a" * 100, "bb" * 60, 012345, 10),
155
- header)
156
- end
157
-
158
- def test_new_from_stream
159
- header = tar_file_header("a" * 100, "", 012345, 10)
160
- h = nil
161
- header = StringIO.new header
162
- assert_nothing_raised{ h = Gem::Package::TarHeader.new_from_stream header }
163
- assert_equal("a" * 100, h.name)
164
- assert_equal(012345, h.mode)
165
- assert_equal(10, h.size)
166
- assert_equal("", h.prefix)
167
- assert_equal("ustar", h.magic)
168
- end
169
-
170
- end
171
-
172
- class TestTarInput < TarTestCase
173
-
174
- # Sometimes the setgid bit doesn't take. Don't know if this
175
- # is a problem on all systems, or just some. But for now, we
176
- # will ignore it in the tests.
177
- SETGID_BIT = 02000
178
-
179
- def setup
180
- FileUtils.mkdir_p "data__"
181
- inner_tar = tar_file_header("bla", "", 0612, 10)
182
- inner_tar += "0123456789" + "\0" * 502
183
- inner_tar += tar_file_header("foo", "", 0636, 5)
184
- inner_tar += "01234" + "\0" * 507
185
- inner_tar += tar_dir_header("__dir__", "", 0600)
186
- inner_tar += "\0" * 1024
187
- str = StringIO.new ""
188
- begin
189
- os = Zlib::GzipWriter.new str
190
- os.write inner_tar
191
- ensure
192
- os.finish
193
- end
194
- str.rewind
195
- File.open("data__/bla.tar", "wb") do |f|
196
- f.write tar_file_header("data.tar.gz", "", 0644, str.string.size)
197
- f.write str.string
198
- f.write "\0" * ((512 - (str.string.size % 512)) % 512 )
199
- @spec = Gem::Specification.new do |spec|
200
- spec.author = "Mauricio :)"
201
- end
202
- meta = @spec.to_yaml
203
- f.write tar_file_header("metadata", "", 0644, meta.size)
204
- f.write meta + "\0" * (1024 - meta.size)
205
- f.write "\0" * 1024
206
- end
207
- @file = "data__/bla.tar"
208
- @entry_names = %w{bla foo __dir__}
209
- @entry_sizes = [10, 5, 0]
210
- #FIXME: are these modes system dependent?
211
- @entry_modes = [0100612, 0100636, 040600]
212
- @entry_files = %w{data__/bla data__/foo}
213
- @entry_contents = %w[0123456789 01234]
214
- end
215
-
216
- def teardown
217
- # FileUtils.rm_rf "data__"
218
- end
219
-
220
- def test_each_works
221
- Gem::Package::TarInput.open(@file) do |is|
222
- count = 0
223
-
224
- is.each_with_index do |entry, i|
225
- count = i
226
-
227
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
228
- assert_equal(@entry_names[i], entry.name)
229
- assert_equal(@entry_sizes[i], entry.size)
230
- end
231
-
232
- assert_equal 2, count
233
-
234
- assert_equal @spec, is.metadata
235
- end
236
- end
237
-
238
- def test_extract_entry_works
239
- Gem::Package::TarInput.open(@file) do |is|
240
- assert_equal @spec, is.metadata
241
- count = 0
242
-
243
- is.each_with_index do |entry, i|
244
- count = i
245
- is.extract_entry "data__", entry
246
- name = File.join("data__", entry.name)
247
-
248
- if entry.is_directory?
249
- assert File.dir?(name)
250
- else
251
- assert File.file?(name)
252
- assert_equal(@entry_sizes[i], File.stat(name).size)
253
- #FIXME: win32? !!
254
- end
255
-
256
- unless ::Config::CONFIG["arch"] =~ /msdos|win32/i
257
- assert_equal(@entry_modes[i],
258
- File.stat(name).mode & (~SETGID_BIT))
259
- end
260
- end
261
-
262
- assert_equal 2, count
263
- end
264
-
265
- @entry_files.each_with_index do |x, i|
266
- assert(File.file?(x))
267
- assert_equal(@entry_contents[i], File.read_b(x))
268
- end
269
- end
270
-
271
- end
272
-
273
- class TestTarOutput < TarTestCase
274
-
275
- def setup
276
- FileUtils.mkdir_p "data__", :verbose=>false
277
- @file = "data__/bla2.tar"
278
- end
279
-
280
- def teardown
281
- FileUtils.rm_rf "data__"
282
- end
283
-
284
- def test_file_looks_good
285
- Gem::Package::TarOutput.open(@file) do |os|
286
- os.metadata = "bla".to_yaml
287
- end
288
- f = File.open(@file, "rb")
289
- Gem::Package::TarReader.new(f) do |is|
290
- i = 0
291
- is.each do |entry|
292
- case i
293
- when 0
294
- assert_equal("data.tar.gz", entry.name)
295
- when 1
296
- assert_equal("metadata.gz", entry.name)
297
- gzis = Zlib::GzipReader.new entry
298
- assert_equal("bla".to_yaml, gzis.read)
299
- gzis.close
300
- end
301
- i += 1
302
- end
303
- assert_equal(2, i)
304
- end
305
- ensure
306
- f.close
307
- end
308
-
309
- end
310
-
311
- class TestTarReader < TarTestCase
312
-
313
- def test_eof_works
314
- str = tar_file_header("bar", "baz", 0644, 0)
315
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
316
- is.each_entry do |entry|
317
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
318
- data = entry.read
319
- assert_equal(nil, data)
320
- assert_equal(nil, entry.read(10))
321
- assert_equal(nil, entry.read)
322
- assert_equal(nil, entry.getc)
323
- assert_equal(true, entry.eof?)
324
- end
325
- end
326
- str = tar_dir_header("foo", "bar", 012345)
327
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
328
- is.each_entry do |entry|
329
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
330
- data = entry.read
331
- assert_equal(nil, data)
332
- assert_equal(nil, entry.read(10))
333
- assert_equal(nil, entry.read)
334
- assert_equal(nil, entry.getc)
335
- assert_equal(true, entry.eof?)
336
- end
337
- end
338
- str = tar_dir_header("foo", "bar", 012345)
339
- str += tar_file_header("bar", "baz", 0644, 0)
340
- str += tar_file_header("bar", "baz", 0644, 0)
341
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
342
- is.each_entry do |entry|
343
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
344
- data = entry.read
345
- assert_equal(nil, data)
346
- assert_equal(nil, entry.read(10))
347
- assert_equal(nil, entry.read)
348
- assert_equal(nil, entry.getc)
349
- assert_equal(true, entry.eof?)
350
- end
351
- end
352
- end
353
-
354
- def test_multiple_entries
355
- str = tar_file_header("lib/foo", "", 010644, 10) + "\0" * 512
356
- str += tar_file_header("bar", "baz", 0644, 0)
357
- str += tar_dir_header("foo", "bar", 012345)
358
- str += "\0" * 1024
359
- names = %w[lib/foo bar foo]
360
- prefixes = ["", "baz", "bar"]
361
- modes = [010644, 0644, 012345]
362
- sizes = [10, 0, 0]
363
- isdir = [false, false, true]
364
- isfile = [true, true, false]
365
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
366
- i = 0
367
- is.each_entry do |entry|
368
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
369
- assert_equal(names[i], entry.name)
370
- assert_equal(prefixes[i], entry.prefix)
371
- assert_equal(sizes[i], entry.size)
372
- assert_equal(modes[i], entry.mode)
373
- assert_equal(isdir[i], entry.is_directory?)
374
- assert_equal(isfile[i], entry.is_file?)
375
- if prefixes[i] != ""
376
- assert_equal(File.join(prefixes[i], names[i]),
377
- entry.full_name)
378
- else
379
- assert_equal(names[i], entry.name)
380
- end
381
- i += 1
382
- end
383
- assert_equal(names.size, i)
384
- end
385
- end
386
-
387
- def test_read_works
388
- contents = ('a'..'z').inject(""){|s,x| s << x * 100}
389
- str = tar_file_header("lib/foo", "", 010644, contents.size) + contents
390
- str += "\0" * (512 - (str.size % 512))
391
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
392
- is.each_entry do |entry|
393
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
394
- data = entry.read(3000) # bigger than contents.size
395
- assert_equal(contents, data)
396
- assert_equal(true, entry.eof?)
397
- end
398
- end
399
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
400
- is.each_entry do |entry|
401
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
402
- data = entry.read(100)
403
- (entry.size - data.size).times {|i| data << entry.getc.chr }
404
- assert_equal(contents, data)
405
- assert_equal(nil, entry.read(10))
406
- assert_equal(true, entry.eof?)
407
- end
408
- end
409
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
410
- is.each_entry do |entry|
411
- assert_kind_of(Gem::Package::TarReader::Entry, entry)
412
- data = entry.read
413
- assert_equal(contents, data)
414
- assert_equal(nil, entry.read(10))
415
- assert_equal(nil, entry.read)
416
- assert_equal(nil, entry.getc)
417
- assert_equal(true, entry.eof?)
418
- end
419
- end
420
- end
421
-
422
- def test_rewind_entry_works
423
- content = ('a'..'z').to_a.join(" ")
424
- str = tar_file_header("lib/foo", "", 010644, content.size) + content +
425
- "\0" * (512 - content.size)
426
- str << "\0" * 1024
427
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
428
- is.each_entry do |entry|
429
- 3.times do
430
- entry.rewind
431
- assert_equal(content, entry.read)
432
- assert_equal(content.size, entry.pos)
433
- end
434
- end
435
- end
436
- end
437
-
438
- def test_rewind_works
439
- content = ('a'..'z').to_a.join(" ")
440
- str = tar_file_header("lib/foo", "", 010644, content.size) + content +
441
- "\0" * (512 - content.size)
442
- str << "\0" * 1024
443
- Gem::Package::TarReader.new(StringIO.new(str)) do |is|
444
- 3.times do
445
- is.rewind
446
- i = 0
447
- is.each_entry do |entry|
448
- assert_equal(content, entry.read)
449
- i += 1
450
- end
451
- assert_equal(1, i)
452
- end
453
- end
454
- end
455
-
456
- end
457
-
458
- class TestTarWriter < TarTestCase
459
-
460
- class DummyIO
461
- attr_reader :data
462
- def initialize
463
- @data = ""
464
- end
465
- def write(dat)
466
- data << dat
467
- dat.size
468
- end
469
- def reset
470
- @data = ""
471
- end
472
- end
473
-
474
- def setup
475
- @data = "a" * 10
476
- @dummyos = DummyIO.new
477
- @os = Gem::Package::TarWriter.new(@dummyos)
478
- end
479
-
480
- def teardown
481
- @os.close
482
- end
483
-
484
- def test_add_file
485
- dummyos = StringIO.new
486
- class << dummyos
487
- def method_missing(meth, *a)
488
- self.string.send(meth, *a)
489
- end
490
- end
491
- os = Gem::Package::TarWriter.new dummyos
492
- content1 = ('a'..'z').to_a.join("") # 26
493
- content2 = ('aa'..'zz').to_a.join("") # 1352
494
- Gem::Package::TarWriter.new(dummyos) do |os|
495
- os.add_file("lib/foo/bar", 0644) {|f| f.write "a" * 10 }
496
- os.add_file("lib/bar/baz", 0644) {|f| f.write content1 }
497
- os.add_file("lib/bar/baz", 0644) {|f| f.write content2 }
498
- os.add_file("lib/bar/baz", 0644) {|f| }
499
- end
500
- assert_headers_equal(tar_file_header("lib/foo/bar", "", 0644, 10),
501
- dummyos[0,512])
502
- assert_equal("a" * 10 + "\0" * 502, dummyos[512,512])
503
- offset = 512 * 2
504
- [content1, content2, ""].each do |data|
505
- assert_headers_equal(tar_file_header("lib/bar/baz", "", 0644,
506
- data.size),
507
- dummyos[offset,512])
508
- offset += 512
509
- until !data || data == ""
510
- chunk = data[0,512]
511
- data[0,512] = ""
512
- assert_equal(chunk + "\0" * (512-chunk.size),
513
- dummyos[offset,512])
514
- offset += 512
515
- end
516
- end
517
- assert_equal("\0" * 1024, dummyos[offset,1024])
518
- end
519
-
520
- def test_add_file_simple
521
- @dummyos.reset
522
- Gem::Package::TarWriter.new(@dummyos) do |os|
523
- os.add_file_simple("lib/foo/bar", 0644, 10) {|f| f.write "a" * 10 }
524
- os.add_file_simple("lib/bar/baz", 0644, 100) {|f| f.write "fillme"}
525
- end
526
- assert_headers_equal(tar_file_header("lib/foo/bar", "", 0644, 10),
527
- @dummyos.data[0,512])
528
- assert_equal("a" * 10 + "\0" * 502, @dummyos.data[512,512])
529
- assert_headers_equal(tar_file_header("lib/bar/baz", "", 0644, 100),
530
- @dummyos.data[512*2,512])
531
- assert_equal("fillme" + "\0" * 506, @dummyos.data[512*3,512])
532
- assert_equal("\0" * 512, @dummyos.data[512*4, 512])
533
- assert_equal("\0" * 512, @dummyos.data[512*5, 512])
534
- end
535
-
536
- def test_add_file_tests_seekability
537
- assert_raises(Gem::Package::NonSeekableIO) do
538
- @os.add_file("libdfdsfd", 0644) {|f| }
539
- end
540
- end
541
-
542
- def test_file_name_is_split_correctly
543
- # test insane file lengths, and
544
- # a{100}/b{155}, etc
545
- @dummyos.reset
546
- names = ["a" * 155 + '/' + "b" * 100, "a" * 151 + "/" + ("qwer/" * 19) + "bla" ]
547
- o_names = ["b" * 100, "qwer/" * 19 + "bla"]
548
- o_prefixes = ["a" * 155, "a" * 151]
549
- names.each {|name| @os.add_file_simple(name, 0644, 10) { } }
550
- o_names.each_with_index do |nam, i|
551
- assert_headers_equal(tar_file_header(nam, o_prefixes[i], 0644, 10),
552
- @dummyos.data[2*i*512,512])
553
- end
554
- assert_raises(Gem::Package::TooLongFileName) do
555
- @os.add_file_simple(File.join("a" * 152, "b" * 10, "a" * 92), 0644,10) {}
556
- end
557
- assert_raises(Gem::Package::TooLongFileName) do
558
- @os.add_file_simple(File.join("a" * 162, "b" * 10), 0644,10) {}
559
- end
560
- assert_raises(Gem::Package::TooLongFileName) do
561
- @os.add_file_simple(File.join("a" * 10, "b" * 110), 0644,10) {}
562
- end
563
- end
564
-
565
- def test_file_size_is_checked
566
- @dummyos.reset
567
- assert_raises(Gem::Package::TarWriter::FileOverflow) do
568
- @os.add_file_simple("lib/foo/bar", 0644, 10) {|f| f.write "1" * 100}
569
- end
570
- assert_nothing_raised do
571
- @os.add_file_simple("lib/foo/bar", 0644, 10) {|f| }
572
- end
573
- end
574
-
575
- def test_write_data
576
- @dummyos.reset
577
- @os.add_file_simple("lib/foo/bar", 0644, 10) { |f| f.write @data }
578
- @os.flush
579
- assert_equal(@data + ("\0" * (512-@data.size)),
580
- @dummyos.data[512,512])
581
- end
582
-
583
- def test_write_header
584
- @dummyos.reset
585
- @os.add_file_simple("lib/foo/bar", 0644, 0) { |f| }
586
- @os.flush
587
- assert_headers_equal(tar_file_header("lib/foo/bar", "", 0644, 0),
588
- @dummyos.data[0,512])
589
- @dummyos.reset
590
- @os.mkdir("lib/foo", 0644)
591
- assert_headers_equal(tar_dir_header("lib/foo", "", 0644),
592
- @dummyos.data[0,512])
593
- @os.mkdir("lib/bar", 0644)
594
- assert_headers_equal(tar_dir_header("lib/bar", "", 0644),
595
- @dummyos.data[512*1,512])
596
- end
597
-
598
- def test_write_operations_fail_after_closed
599
- @dummyos.reset
600
- @os.add_file_simple("sadd", 0644, 20) { |f| }
601
- @os.close
602
- assert_raises(Gem::Package::ClosedIO) { @os.flush }
603
- assert_raises(Gem::Package::ClosedIO) { @os.add_file("dfdsf", 0644){} }
604
- assert_raises(Gem::Package::ClosedIO) { @os.mkdir "sdfdsf", 0644 }
605
- end
606
-
607
- end
608
-