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.
- data.tar.gz.sig +0 -0
- data/ChangeLog +248 -0
- data/README +2 -0
- data/Rakefile +47 -23
- data/bin/gem +9 -4
- data/bin/update_rubygems +15 -1
- data/examples/application/bin/myapp +0 -0
- data/lib/rubygems.rb +506 -373
- data/lib/rubygems/builder.rb +14 -7
- data/lib/rubygems/command.rb +9 -9
- data/lib/rubygems/command_manager.rb +1 -0
- data/lib/rubygems/commands/cleanup_command.rb +67 -69
- data/lib/rubygems/commands/environment_command.rb +16 -10
- data/lib/rubygems/commands/fetch_command.rb +7 -9
- data/lib/rubygems/commands/install_command.rb +9 -3
- data/lib/rubygems/commands/list_command.rb +2 -4
- data/lib/rubygems/commands/mirror_command.rb +1 -1
- data/lib/rubygems/commands/query_command.rb +52 -5
- data/lib/rubygems/commands/sources_command.rb +19 -10
- data/lib/rubygems/commands/specification_command.rb +10 -6
- data/lib/rubygems/commands/uninstall_command.rb +23 -6
- data/lib/rubygems/commands/unpack_command.rb +15 -3
- data/lib/rubygems/commands/update_command.rb +27 -25
- data/lib/rubygems/custom_require.rb +1 -1
- data/lib/rubygems/defaults.rb +8 -1
- data/lib/rubygems/dependency_installer.rb +72 -104
- data/lib/rubygems/digest/digest_adapter.rb +0 -0
- data/lib/rubygems/digest/md5.rb +0 -0
- data/lib/rubygems/digest/sha1.rb +0 -0
- data/lib/rubygems/digest/sha2.rb +0 -0
- data/lib/rubygems/exceptions.rb +22 -1
- data/lib/rubygems/format.rb +16 -10
- data/lib/rubygems/indexer.rb +46 -33
- data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
- data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
- data/lib/rubygems/indexer/master_index_builder.rb +9 -8
- data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
- data/lib/rubygems/install_update_options.rb +7 -1
- data/lib/rubygems/installer.rb +8 -5
- data/lib/rubygems/package.rb +17 -774
- data/lib/rubygems/package/f_sync_dir.rb +24 -0
- data/lib/rubygems/package/tar_header.rb +245 -0
- data/lib/rubygems/package/tar_input.rb +219 -0
- data/lib/rubygems/package/tar_output.rb +143 -0
- data/lib/rubygems/package/tar_reader.rb +86 -0
- data/lib/rubygems/package/tar_reader/entry.rb +99 -0
- data/lib/rubygems/package/tar_writer.rb +180 -0
- data/lib/rubygems/remote_fetcher.rb +131 -16
- data/lib/rubygems/requirement.rb +2 -0
- data/lib/rubygems/rubygems_version.rb +1 -1
- data/lib/rubygems/security.rb +1 -0
- data/lib/rubygems/server.rb +85 -104
- data/lib/rubygems/source_index.rb +412 -329
- data/lib/rubygems/source_info_cache.rb +232 -99
- data/lib/rubygems/source_info_cache_entry.rb +14 -4
- data/lib/rubygems/specification.rb +9 -10
- data/lib/rubygems/timer.rb +0 -0
- data/lib/rubygems/uninstaller.rb +56 -32
- data/lib/rubygems/user_interaction.rb +4 -10
- data/lib/rubygems/validator.rb +0 -0
- data/scripts/gemdoc.rb +0 -0
- data/scripts/specdoc.rb +0 -0
- data/setup.rb +56 -19
- data/test/gem_installer_test_case.rb +86 -0
- data/test/gem_installer_test_case.rbc +0 -0
- data/test/gem_package_tar_test_case.rb +146 -0
- data/test/gem_package_tar_test_case.rbc +0 -0
- data/test/gemutilities.rb +123 -38
- data/test/gemutilities.rbc +0 -0
- data/test/mockgemui.rb +5 -13
- data/test/mockgemui.rbc +0 -0
- data/test/private_key.pem +27 -0
- data/test/public_cert.pem +20 -0
- data/test/simple_gem.rbc +0 -0
- data/test/test_config.rbc +0 -0
- data/test/test_gem.rb +46 -4
- data/test/test_gem.rbc +0 -0
- data/test/test_gem_builder.rbc +0 -0
- data/test/test_gem_command.rbc +0 -0
- data/test/test_gem_command_manager.rb +4 -2
- data/test/test_gem_command_manager.rbc +0 -0
- data/test/test_gem_commands_build_command.rbc +0 -0
- data/test/test_gem_commands_cert_command.rb +5 -1
- data/test/test_gem_commands_cert_command.rbc +0 -0
- data/test/test_gem_commands_check_command.rbc +0 -0
- data/test/test_gem_commands_contents_command.rbc +0 -0
- data/test/test_gem_commands_dependency_command.rbc +0 -0
- data/test/test_gem_commands_environment_command.rb +17 -1
- data/test/test_gem_commands_environment_command.rbc +0 -0
- data/test/test_gem_commands_fetch_command.rb +6 -5
- data/test/test_gem_commands_fetch_command.rbc +0 -0
- data/test/test_gem_commands_generate_index_command.rbc +0 -0
- data/test/test_gem_commands_install_command.rb +36 -28
- data/test/test_gem_commands_install_command.rbc +0 -0
- data/test/test_gem_commands_mirror_command.rbc +0 -0
- data/test/test_gem_commands_pristine_command.rbc +0 -0
- data/test/test_gem_commands_query_command.rb +143 -19
- data/test/test_gem_commands_query_command.rbc +0 -0
- data/test/test_gem_commands_server_command.rb +1 -1
- data/test/test_gem_commands_server_command.rbc +0 -0
- data/test/test_gem_commands_sources_command.rb +67 -9
- data/test/test_gem_commands_sources_command.rbc +0 -0
- data/test/test_gem_commands_specification_command.rb +3 -2
- data/test/test_gem_commands_specification_command.rbc +0 -0
- data/test/test_gem_commands_unpack_command.rb +46 -4
- data/test/test_gem_commands_unpack_command.rbc +0 -0
- data/test/test_gem_commands_update_command.rb +174 -0
- data/test/test_gem_commands_update_command.rbc +0 -0
- data/test/test_gem_config_file.rbc +0 -0
- data/test/test_gem_dependency.rbc +0 -0
- data/test/test_gem_dependency_installer.rb +172 -187
- data/test/test_gem_dependency_installer.rbc +0 -0
- data/test/test_gem_dependency_list.rbc +0 -0
- data/test/test_gem_digest.rb +0 -0
- data/test/test_gem_digest.rbc +0 -0
- data/test/test_gem_doc_manager.rbc +0 -0
- data/test/test_gem_ext_configure_builder.rb +9 -6
- data/test/test_gem_ext_configure_builder.rbc +0 -0
- data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
- data/test/test_gem_ext_rake_builder.rbc +0 -0
- data/test/test_gem_format.rb +1 -1
- data/test/test_gem_format.rbc +0 -0
- data/test/test_gem_gem_path_searcher.rbc +0 -0
- data/test/test_gem_gem_runner.rbc +0 -0
- data/test/test_gem_indexer.rb +7 -2
- data/test/test_gem_indexer.rbc +0 -0
- data/test/test_gem_install_update_options.rbc +0 -0
- data/test/test_gem_installer.rb +5 -84
- data/test/test_gem_installer.rbc +0 -0
- data/test/test_gem_local_remote_options.rbc +0 -0
- data/test/test_gem_outdated_command.rbc +0 -0
- data/test/test_gem_package_tar_header.rb +137 -0
- data/test/test_gem_package_tar_header.rbc +0 -0
- data/test/test_gem_package_tar_input.rb +119 -0
- data/test/test_gem_package_tar_input.rbc +0 -0
- data/test/test_gem_package_tar_output.rb +104 -0
- data/test/test_gem_package_tar_output.rbc +0 -0
- data/test/test_gem_package_tar_reader.rb +53 -0
- data/test/test_gem_package_tar_reader.rbc +0 -0
- data/test/test_gem_package_tar_reader_entry.rb +116 -0
- data/test/test_gem_package_tar_reader_entry.rbc +0 -0
- data/test/test_gem_package_tar_writer.rb +151 -0
- data/test/test_gem_package_tar_writer.rbc +0 -0
- data/test/test_gem_platform.rbc +0 -0
- data/test/test_gem_remote_fetcher.rb +189 -17
- data/test/test_gem_remote_fetcher.rbc +0 -0
- data/test/test_gem_requirement.rbc +0 -0
- data/test/test_gem_server.rb +13 -12
- data/test/test_gem_server.rbc +0 -0
- data/test/test_gem_source_index.rb +305 -56
- data/test/test_gem_source_index.rbc +0 -0
- data/test/test_gem_source_info_cache.rb +179 -53
- data/test/test_gem_source_info_cache.rbc +0 -0
- data/test/test_gem_source_info_cache_entry.rb +41 -10
- data/test/test_gem_source_info_cache_entry.rbc +0 -0
- data/test/test_gem_specification.rb +7 -7
- data/test/test_gem_specification.rbc +0 -0
- data/test/test_gem_stream_ui.rbc +0 -0
- data/test/test_gem_uninstaller.rb +43 -0
- data/test/test_gem_uninstaller.rbc +0 -0
- data/test/test_gem_validator.rbc +0 -0
- data/test/test_gem_version.rb +1 -1
- data/test/test_gem_version.rbc +0 -0
- data/test/test_gem_version_option.rbc +0 -0
- data/test/test_kernel.rb +1 -0
- data/test/test_kernel.rbc +0 -0
- metadata +85 -8
- metadata.gz.sig +0 -0
- data/lib/rubygems/gem_open_uri.rb +0 -7
- data/lib/rubygems/open-uri.rb +0 -773
- data/test/test_open_uri.rb +0 -13
- 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
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
109
|
-
|
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
|
-
|
127
|
-
|
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
|
-
|
142
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
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,
|
196
|
-
|
353
|
+
open cache_file, 'wb' do |io|
|
354
|
+
io.write Marshal.dump(cache_data)
|
197
355
|
end
|
198
|
-
end
|
199
356
|
|
200
|
-
|
201
|
-
|
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
|
-
#
|
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
|
-
|
33
|
-
|
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
|