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
@@ -4,6 +4,7 @@ require 'rubygems'
4
4
  require 'rubygems/source_info_cache_entry'
5
5
  require 'rubygems/user_interaction'
6
6
 
7
+ ##
7
8
  # SourceInfoCache stores a copy of the gem index for each gem source.
8
9
  #
9
10
  # There are two possible cache locations, the system cache and the user cache:
@@ -25,19 +26,19 @@ require 'rubygems/user_interaction'
25
26
  # @source_index => Gem::SourceIndex
26
27
  # ...
27
28
  # }
28
- #
29
+
29
30
  class Gem::SourceInfoCache
30
31
 
31
32
  include Gem::UserInteraction
32
33
 
33
- @cache = nil
34
- @system_cache_file = nil
35
- @user_cache_file = nil
34
+ ##
35
+ # The singleton Gem::SourceInfoCache. If +all+ is true, a full refresh will
36
+ # be performed if the singleton instance is being initialized.
36
37
 
37
- def self.cache
38
+ def self.cache(all = false)
38
39
  return @cache if @cache
39
40
  @cache = new
40
- @cache.refresh if Gem.configuration.update_sources
41
+ @cache.refresh all if Gem.configuration.update_sources
41
42
  @cache
42
43
  end
43
44
 
@@ -45,71 +46,85 @@ class Gem::SourceInfoCache
45
46
  cache.cache_data
46
47
  end
47
48
 
48
- # Search all source indexes for +pattern+.
49
- def self.search(pattern, platform_only = false)
50
- cache.search pattern, platform_only
49
+ ##
50
+ # The name of the system cache file.
51
+
52
+ def self.latest_system_cache_file
53
+ File.join File.dirname(system_cache_file),
54
+ "latest_#{File.basename system_cache_file}"
55
+ end
56
+
57
+ ##
58
+ # The name of the latest user cache file.
59
+
60
+ def self.latest_user_cache_file
61
+ File.join File.dirname(user_cache_file),
62
+ "latest_#{File.basename user_cache_file}"
51
63
  end
52
64
 
53
- # Search all source indexes for +pattern+. Only returns gems matching
54
- # Gem.platforms when +only_platform+ is true. See #search_with_source.
55
- def self.search_with_source(pattern, only_platform = false)
56
- cache.search_with_source(pattern, only_platform)
65
+ ##
66
+ # Reset all singletons, discarding any changes.
67
+
68
+ def self.reset
69
+ @cache = nil
70
+ @system_cache_file = nil
71
+ @user_cache_file = nil
72
+ end
73
+
74
+ ##
75
+ # Search all source indexes. See Gem::SourceInfoCache#search.
76
+
77
+ def self.search(*args)
78
+ cache.search(*args)
79
+ end
80
+
81
+ ##
82
+ # Search all source indexes returning the source_uri. See
83
+ # Gem::SourceInfoCache#search_with_source.
84
+
85
+ def self.search_with_source(*args)
86
+ cache.search_with_source(*args)
87
+ end
88
+
89
+ ##
90
+ # The name of the system cache file. (class method)
91
+
92
+ def self.system_cache_file
93
+ @system_cache_file ||= Gem.default_system_source_cache_dir
94
+ end
95
+
96
+ ##
97
+ # The name of the user cache file.
98
+
99
+ def self.user_cache_file
100
+ @user_cache_file ||=
101
+ ENV['GEMCACHE'] || Gem.default_user_source_cache_dir
57
102
  end
58
103
 
59
104
  def initialize # :nodoc:
60
105
  @cache_data = nil
61
106
  @cache_file = nil
62
107
  @dirty = false
108
+ @only_latest = true
63
109
  end
64
110
 
111
+ ##
65
112
  # The most recent cache data.
113
+
66
114
  def cache_data
67
115
  return @cache_data if @cache_data
68
116
  cache_file # HACK writable check
69
117
 
70
- begin
71
- # Marshal loads 30-40% faster from a String, and 2MB on 20061116 is small
72
- data = File.open cache_file, 'rb' do |fp| fp.read end
73
- @cache_data = Marshal.load data
74
-
75
- @cache_data.each do |url, sice|
76
- next unless sice.is_a?(Hash)
77
- update
78
- cache = sice['cache']
79
- size = sice['size']
80
- if cache.is_a?(Gem::SourceIndex) and size.is_a?(Numeric) then
81
- new_sice = Gem::SourceInfoCacheEntry.new cache, size
82
- @cache_data[url] = new_sice
83
- else # irreperable, force refetch.
84
- reset_cache_for(url)
85
- end
86
- end
87
- @cache_data
88
- rescue => e
89
- if Gem.configuration.really_verbose then
90
- say "Exception during cache_data handling: #{ex.class} - #{ex}"
91
- say "Cache file was: #{cache_file}"
92
- say "\t#{e.backtrace.join "\n\t"}"
93
- end
94
- reset_cache_data
95
- end
96
- end
118
+ @only_latest = true
97
119
 
98
- def reset_cache_for(url)
99
- say "Reseting cache for #{url}" if Gem.configuration.really_verbose
120
+ @cache_data = read_cache_data latest_cache_file
100
121
 
101
- sice = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
102
- sice.refresh url # HACK may be unnecessary, see ::cache and #refresh
103
-
104
- @cache_data[url] = sice
105
122
  @cache_data
106
123
  end
107
124
 
108
- def reset_cache_data
109
- @cache_data = {}
110
- end
125
+ ##
126
+ # The name of the cache file.
111
127
 
112
- # The name of the cache file to be read
113
128
  def cache_file
114
129
  return @cache_file if @cache_file
115
130
  @cache_file = (try_file(system_cache_file) or
@@ -117,14 +132,94 @@ class Gem::SourceInfoCache
117
132
  raise "unable to locate a writable cache file")
118
133
  end
119
134
 
135
+ ##
120
136
  # Write the cache to a local file (if it is dirty).
137
+
121
138
  def flush
122
139
  write_cache if @dirty
123
140
  @dirty = false
124
141
  end
125
142
 
126
- # Refreshes each source in the cache from its repository.
127
- def refresh
143
+ def latest_cache_data
144
+ latest_cache_data = {}
145
+
146
+ cache_data.each do |repo, sice|
147
+ latest = sice.source_index.latest_specs
148
+
149
+ new_si = Gem::SourceIndex.new
150
+ new_si.add_specs(*latest)
151
+
152
+ latest_sice = Gem::SourceInfoCacheEntry.new new_si, sice.size
153
+ latest_cache_data[repo] = latest_sice
154
+ end
155
+
156
+ latest_cache_data
157
+ end
158
+
159
+ ##
160
+ # The name of the latest cache file.
161
+
162
+ def latest_cache_file
163
+ File.join File.dirname(cache_file), "latest_#{File.basename cache_file}"
164
+ end
165
+
166
+ ##
167
+ # The name of the latest system cache file.
168
+
169
+ def latest_system_cache_file
170
+ self.class.latest_system_cache_file
171
+ end
172
+
173
+ ##
174
+ # The name of the latest user cache file.
175
+
176
+ def latest_user_cache_file
177
+ self.class.latest_user_cache_file
178
+ end
179
+
180
+ def read_all_cache_data
181
+ if @only_latest then
182
+ @only_latest = false
183
+ @cache_data = read_cache_data cache_file
184
+ end
185
+ end
186
+
187
+ def read_cache_data(file)
188
+ # Marshal loads 30-40% faster from a String, and 2MB on 20061116 is small
189
+ data = open file, 'rb' do |fp| fp.read end
190
+ cache_data = Marshal.load data
191
+
192
+ cache_data.each do |url, sice|
193
+ next unless sice.is_a?(Hash)
194
+ update
195
+
196
+ cache = sice['cache']
197
+ size = sice['size']
198
+
199
+ if cache.is_a?(Gem::SourceIndex) and size.is_a?(Numeric) then
200
+ new_sice = Gem::SourceInfoCacheEntry.new cache, size
201
+ cache_data[url] = new_sice
202
+ else # irreperable, force refetch.
203
+ reset_cache_for url, cache_data
204
+ end
205
+ end
206
+
207
+ cache_data
208
+ rescue => e
209
+ if Gem.configuration.really_verbose then
210
+ say "Exception during cache_data handling: #{e.class} - #{e}"
211
+ say "Cache file was: #{file}"
212
+ say "\t#{e.backtrace.join "\n\t"}"
213
+ end
214
+
215
+ {}
216
+ end
217
+
218
+ ##
219
+ # Refreshes each source in the cache from its repository. If +all+ is
220
+ # false, only latest gems are updated.
221
+
222
+ def refresh(all)
128
223
  Gem.sources.each do |source_uri|
129
224
  cache_entry = cache_data[source_uri]
130
225
  if cache_entry.nil? then
@@ -132,14 +227,41 @@ class Gem::SourceInfoCache
132
227
  cache_data[source_uri] = cache_entry
133
228
  end
134
229
 
135
- update if cache_entry.refresh source_uri
230
+ update if cache_entry.refresh source_uri, all
136
231
  end
137
232
 
138
233
  flush
139
234
  end
140
235
 
141
- # Searches all source indexes for +pattern+.
142
- def search(pattern, platform_only = false)
236
+ def reset_cache_for(url, cache_data)
237
+ say "Reseting cache for #{url}" if Gem.configuration.really_verbose
238
+
239
+ sice = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
240
+ sice.refresh url, false # HACK may be unnecessary, see ::cache and #refresh
241
+
242
+ cache_data[url] = sice
243
+ cache_data
244
+ end
245
+
246
+ def reset_cache_data
247
+ @cache_data = nil
248
+ end
249
+
250
+ ##
251
+ # Force cache file to be reset, useful for integration testing of rubygems
252
+
253
+ def reset_cache_file
254
+ @cache_file = nil
255
+ end
256
+
257
+ ##
258
+ # Searches all source indexes. See Gem::SourceIndex#search for details on
259
+ # +pattern+ and +platform_only+. If +all+ is set to true, the full index
260
+ # will be loaded before searching.
261
+
262
+ def search(pattern, platform_only = false, all = false)
263
+ read_all_cache_data if all
264
+
143
265
  cache_data.map do |source_uri, sic_entry|
144
266
  next unless Gem.sources.include? source_uri
145
267
  sic_entry.source_index.search pattern, platform_only
@@ -150,7 +272,9 @@ class Gem::SourceInfoCache
150
272
  # only gems matching Gem.platforms will be selected. Returns an Array of
151
273
  # pairs containing the Gem::Specification found and the source_uri it was
152
274
  # found at.
153
- def search_with_source(pattern, only_platform = false)
275
+ def search_with_source(pattern, only_platform = false, all = false)
276
+ read_all_cache_data if all
277
+
154
278
  results = []
155
279
 
156
280
  cache_data.map do |source_uri, sic_entry|
@@ -164,69 +288,78 @@ class Gem::SourceInfoCache
164
288
  results
165
289
  end
166
290
 
167
- # Mark the cache as updated (i.e. dirty).
168
- def update
169
- @dirty = true
291
+ ##
292
+ # Set the source info cache data directly. This is mainly used for unit
293
+ # testing when we don't want to read a file system to grab the cached source
294
+ # index information. The +hash+ should map a source URL into a
295
+ # SourceInfoCacheEntry.
296
+
297
+ def set_cache_data(hash)
298
+ @cache_data = hash
299
+ update
170
300
  end
171
301
 
302
+ ##
172
303
  # The name of the system cache file.
304
+
173
305
  def system_cache_file
174
306
  self.class.system_cache_file
175
307
  end
176
308
 
177
- # The name of the system cache file. (class method)
178
- def self.system_cache_file
179
- @system_cache_file ||= Gem.default_system_source_cache_dir
309
+ ##
310
+ # Determine if +path+ is a candidate for a cache file. Returns +path+ if
311
+ # it is, nil if not.
312
+
313
+ def try_file(path)
314
+ return path if File.writable? path
315
+ return nil if File.exist? path
316
+
317
+ dir = File.dirname path
318
+
319
+ unless File.exist? dir then
320
+ begin
321
+ FileUtils.mkdir_p dir
322
+ rescue RuntimeError, SystemCallError
323
+ return nil
324
+ end
325
+ end
326
+
327
+ if File.writable? dir then
328
+ open path, "wb" do |io| io.write Marshal.dump({}) end
329
+ return path
330
+ end
331
+
332
+ nil
333
+ end
334
+
335
+ ##
336
+ # Mark the cache as updated (i.e. dirty).
337
+
338
+ def update
339
+ @dirty = true
180
340
  end
181
341
 
342
+ ##
182
343
  # The name of the user cache file.
344
+
183
345
  def user_cache_file
184
346
  self.class.user_cache_file
185
347
  end
186
348
 
187
- # The name of the user cache file. (class method)
188
- def self.user_cache_file
189
- @user_cache_file ||=
190
- ENV['GEMCACHE'] || Gem.default_user_source_cache_dir
191
- end
192
-
349
+ ##
193
350
  # Write data to the proper cache.
351
+
194
352
  def write_cache
195
- open cache_file, "wb" do |f|
196
- f.write Marshal.dump(cache_data)
353
+ open cache_file, 'wb' do |io|
354
+ io.write Marshal.dump(cache_data)
197
355
  end
198
- end
199
356
 
200
- # Set the source info cache data directly. This is mainly used for unit
201
- # testing when we don't want to read a file system to grab the cached source
202
- # index information. The +hash+ should map a source URL into a
203
- # SourceInfoCacheEntry.
204
- def set_cache_data(hash)
205
- @cache_data = hash
206
- update
207
- end
208
-
209
- private
210
-
211
- # Determine if +fn+ is a candidate for a cache file. Return fn if
212
- # it is. Return nil if it is not.
213
- def try_file(fn)
214
- return fn if File.writable?(fn)
215
- return nil if File.exist?(fn)
216
- dir = File.dirname(fn)
217
- unless File.exist? dir then
218
- begin
219
- FileUtils.mkdir_p(dir)
220
- rescue RuntimeError, SystemCallError
221
- return nil
222
- end
223
- end
224
- if File.writable?(dir)
225
- File.open(fn, "wb") { |f| f << Marshal.dump({}) }
226
- return fn
357
+ open latest_cache_file, 'wb' do |io|
358
+ io.write Marshal.dump(latest_cache_data)
227
359
  end
228
- nil
229
360
  end
230
361
 
362
+ reset
363
+
231
364
  end
232
365
 
@@ -3,24 +3,31 @@ require 'rubygems/source_index'
3
3
  require 'rubygems/remote_fetcher'
4
4
 
5
5
  ##
6
- # Entrys held by a SourceInfoCache.
6
+ # Entries held by a SourceInfoCache.
7
7
 
8
8
  class Gem::SourceInfoCacheEntry
9
9
 
10
+ ##
10
11
  # The source index for this cache entry.
12
+
11
13
  attr_reader :source_index
12
14
 
15
+ ##
13
16
  # The size of the of the source entry. Used to determine if the
14
17
  # source index has changed.
18
+
15
19
  attr_reader :size
16
20
 
21
+ ##
17
22
  # Create a cache entry.
23
+
18
24
  def initialize(si, size)
19
25
  @source_index = si || Gem::SourceIndex.new({})
20
26
  @size = size
27
+ @all = false
21
28
  end
22
29
 
23
- def refresh(source_uri)
30
+ def refresh(source_uri, all)
24
31
  begin
25
32
  marshal_uri = URI.join source_uri.to_s, "Marshal.#{Gem.marshal_version}"
26
33
  remote_size = Gem::RemoteFetcher.fetcher.fetch_size marshal_uri
@@ -29,9 +36,12 @@ class Gem::SourceInfoCacheEntry
29
36
  remote_size = Gem::RemoteFetcher.fetcher.fetch_size yaml_uri
30
37
  end
31
38
 
32
- return false if @size == remote_size # TODO Use index_signature instead of size?
33
- updated = @source_index.update source_uri
39
+ # TODO Use index_signature instead of size?
40
+ return false if @size == remote_size and @all
41
+
42
+ updated = @source_index.update source_uri, all
34
43
  @size = remote_size
44
+ @all = all
35
45
 
36
46
  updated
37
47
  end